Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cprecioso/micro-protocol
Micro middleware to get the protocol of the request
https://github.com/cprecioso/micro-protocol
Last synced: 3 months ago
JSON representation
Micro middleware to get the protocol of the request
- Host: GitHub
- URL: https://github.com/cprecioso/micro-protocol
- Owner: cprecioso
- Created: 2019-11-17T20:13:52.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T01:03:47.000Z (almost 2 years ago)
- Last Synced: 2024-07-08T00:03:33.320Z (4 months ago)
- Language: TypeScript
- Size: 227 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-micro - micro-protocol - Get the protocol of the request (optionally following proxies). (Modules / HTTP Requests)
README
# `micro-protocol`
Adapted the
[`express.js` algorithm](hthttps://github.com/expressjs/express/blob/b8e50568af9c73ef1ade434e92c60d389868361d/lib/request.js#L306)
to a [`micro`](https://github.com/zeit/micro) middleware.## Installation
```sh
$ npm install micro-protocol
```## Example
```js
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
```js
const protocol = require("micro-protocol").default
```