fast-gateway
Advanced tools
Comparing version 2.5.2 to 2.6.0
{ | ||
"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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23674
8
243
407
17