Skip to content

cprecioso/micro-protocol

Repository files navigation

micro-protocol

Adapted the express.js algorithm to a micro middleware.

Installation

$ npm install micro-protocol

Example

import protocol from "micro-protocol"

export default protocol(
  async (req, res) => {
    console.log(req.protocol) // -> "http", or "https"
  {
    trustProxy: true
    // (Optional - default `false`) Whether to trust the X-Forwarded-Proto if
    // you use a reverse proxy. You can also pass a function that accepts
    // `req.connection.remoteAddress` and returns a boolean whether to trust
    // it.
  }
)

If you don't use a bundler or ES module, you can import like

const protocol = require("micro-protocol").default

About

Micro middleware to get the protocol of the request

Resources

Stars

Watchers

Forks

Packages

No packages published