Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cprecioso/micro-hostname
Micro middleware to get the hostname of the request
https://github.com/cprecioso/micro-hostname
Last synced: about 1 month ago
JSON representation
Micro middleware to get the hostname of the request
- Host: GitHub
- URL: https://github.com/cprecioso/micro-hostname
- Owner: cprecioso
- Created: 2019-11-17T02:31:18.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T01:01:10.000Z (about 2 years ago)
- Last Synced: 2024-11-24T20:44:44.509Z (about 2 months ago)
- Language: TypeScript
- Size: 273 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-micro - micro-hostname - Get the hostname (host without port) of the request (optionally following proxies) (Modules / HTTP Requests)
README
# `micro-hostname`
Adapted the
[`express.js` algorithm](https://github.com/expressjs/express/blob/b8e50568af9c73ef1ade434e92c60d389868361d/lib/request.js#L427)
to a [`micro`](https://github.com/zeit/micro) middleware.## Installation
```sh
$ npm install micro-hostname
```## Example
```js
import hostname from "micro-hostname"export default hostname(
async (req, res) => {
console.log(req.hostname) // -> "localhost", 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
```js
const hostname = require("micro-hostname").default
```