1.1.0 • Published 4 years ago

micro-host v1.1.0

Weekly downloads
38
License
ISC
Repository
github
Last release
4 years ago

micro-host

Adapted the express.js algorithm to a micro middleware.

Installation

$ npm install micro-host

Example

import host from "micro-host"

export default host(
  async (req, res) => {
    console.log(req.host) // -> "localhost:3000", or "my-deploy.now.sh", etc
  },
  {
    trustProxy: true
    // (Optional - default `false`) Whether to trust the X-Forwarded-Host 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 host = require("micro-host").default