Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fast-gateway

Package Overview
Dependencies
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-gateway - npm Package Compare versions

Comparing version 2.5.2 to 2.6.0

lib/hostnames-hook.js

9

package.json
{
"name": "fast-gateway",
"version": "2.5.2",
"version": "2.6.0",
"description": "A Node.js API Gateway for the masses!",

@@ -45,3 +45,3 @@ "main": "index.js",

"@types/express": "^4.17.8",
"aws-sdk": "^2.771.0",
"aws-sdk": "^2.777.0",
"chai": "^4.2.0",

@@ -55,5 +55,6 @@ "cors": "^2.8.5",

"http-lambda-proxy": "^1.0.1",
"mocha": "^8.1.3",
"micromatch": "^4.0.2",
"mocha": "^8.2.0",
"nyc": "^15.1.0",
"opossum": "^5.0.1",
"opossum": "^5.0.2",
"request-ip": "^2.1.3",

@@ -60,0 +61,0 @@ "response-time": "^2.3.2",

@@ -243,2 +243,52 @@ # fast-gateway

## Hostnames support
We can also implement hostnames support with fast-gateway, basically we translate hostnames to prefixes:
```js
...
// binding hostnames to prefixes
const hostnames2prefix = [{
prefix: '/api',
hostname: 'api.company.tld'
}]
// instantiate hostnames hook, this will prefix request urls according to data in hostnames2prefix
const hostnamesHook = require('fast-gateway/lib/hostnames-hook')(hostnames2prefix)
// separately instantiate and configure restana application
const app = restana()
const server = http.createServer((req, res) => {
hostnamesHook(req, res, () => {
return app(req, res)
})
})
// gateway configuration
gateway({
server: app, // injecting existing restana application
routes: [{
prefix: '/api',
target: 'http://localhost:3000'
}]
})
...
```
> Afterwards:
> `curl --header "Host: api.company.tld:8080" http://127.0.0.1:8080/api-service-endpoint`
You can optionally `npm install micromatch` and benefit from patterns support:
```js
const hostnames2prefix = [{
prefix: '/admin',
hostname: '*.admin.company.tld'
}, {
prefix: '/services',
hostname: [
'services.company.tld',
'*.services.company.tld'
]
}]
```
For more details, please checkout the `basic-hostnames.js` demo.
## Gateway level caching

@@ -245,0 +295,0 @@ Caching support is provided by the `http-cache-middleware` module. https://www.npmjs.com/package/http-cache-middleware

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc