fast-gateway
Advanced tools
Comparing version 1.5.2 to 2.0.0
50
index.js
@@ -8,3 +8,3 @@ /* eslint-disable no-useless-call */ | ||
const defaultProxyHandler = (req, res, url, proxy, proxyOpts) => proxy(req, res, url, proxyOpts) | ||
const DEFAULT_METHODS = require('restana/libs/methods') | ||
const DEFAULT_METHODS = require('restana/libs/methods').filter(method => method !== 'all') | ||
const send = require('@polka/send-type') | ||
@@ -18,5 +18,3 @@ | ||
const server = opts.server || ((opts.restana instanceof Function) ? opts.restana() : restana(opts.restana || { | ||
disableResponseEvent: true | ||
})) | ||
const server = opts.server || restana(opts.restana) | ||
@@ -69,14 +67,16 @@ // registering global middlewares | ||
const methods = route.methods || DEFAULT_METHODS | ||
const args = [ | ||
// path | ||
route.prefix + route.pathRegex, | ||
// route middlewares | ||
...route.middlewares, | ||
// route handler | ||
handler(route, proxy, proxyHandler) | ||
] | ||
methods.forEach(method => { | ||
method = method.toLowerCase() | ||
if (server[method]) { | ||
server[method].apply(server, [ | ||
// path | ||
route.prefix + route.pathRegex, | ||
// route middlewares | ||
...route.middlewares, | ||
// route handler | ||
handler(route, proxy, proxyHandler) | ||
]) | ||
server[method].apply(server, args) | ||
} | ||
@@ -89,13 +89,17 @@ }) | ||
const handler = (route, proxy, proxyHandler) => async (req, res) => { | ||
req.url = req.url.replace(route.prefix, route.prefixRewrite) | ||
const shouldAbortProxy = await route.hooks.onRequest(req, res) | ||
if (!shouldAbortProxy) { | ||
const proxyOpts = Object.assign({ | ||
request: { | ||
timeout: req.timeout || route.timeout | ||
} | ||
}, route.hooks) | ||
const handler = (route, proxy, proxyHandler) => async (req, res, next) => { | ||
try { | ||
req.url = req.url.replace(route.prefix, route.prefixRewrite) | ||
const shouldAbortProxy = await route.hooks.onRequest(req, res) | ||
if (!shouldAbortProxy) { | ||
const proxyOpts = Object.assign({ | ||
request: { | ||
timeout: req.timeout || route.timeout | ||
} | ||
}, route.hooks) | ||
proxyHandler(req, res, req.url, proxy, proxyOpts) | ||
proxyHandler(req, res, req.url, proxy, proxyOpts) | ||
} | ||
} catch (err) { | ||
return next(err) | ||
} | ||
@@ -102,0 +106,0 @@ } |
{ | ||
"name": "fast-gateway", | ||
"version": "1.5.2", | ||
"version": "2.0.0", | ||
"description": "A Node.js API Gateway for the masses!", | ||
@@ -32,9 +32,9 @@ "main": "index.js", | ||
"http-cache-middleware": "^1.2.3", | ||
"restana": "^3.4.1", | ||
"restana": "^4.0.3", | ||
"stream-to-array": "^2.3.0" | ||
}, | ||
"devDependencies": { | ||
"express": "^4.17.1", | ||
"chai": "^4.2.0", | ||
"cors": "^2.8.5", | ||
"express": "^4.17.1", | ||
"express-jwt": "^5.3.1", | ||
@@ -45,3 +45,3 @@ "express-rate-limit": "^5.0.0", | ||
"nyc": "^14.1.1", | ||
"opossum": "^4.2.1", | ||
"opossum": "^4.2.2", | ||
"request-ip": "^2.1.3", | ||
@@ -48,0 +48,0 @@ "response-time": "^2.3.2", |
@@ -44,6 +44,5 @@ # fast-gateway | ||
server, | ||
// Optional restana library configuration (https://www.npmjs.com/package/restana#configuration) | ||
// If the given value is a function instead of an object, it will be considered a restana server factory. | ||
// | ||
// If "server" is provided, this settings are ignored. | ||
// Optional restana library configuration (https://www.npmjs.com/package/restana#configuration) | ||
// | ||
// Please note that if "server" is provided, this settings are ignored. | ||
restana: {}, | ||
@@ -50,0 +49,0 @@ // Optional global middlewares in the format: (req, res, next) => next() |
@@ -27,8 +27,12 @@ const pump = require('pump') | ||
}, { | ||
prefix: '/users', | ||
prefix: '/users/response-time', | ||
prefixRewrite: '', | ||
target: 'http://localhost:3000', | ||
docs: { | ||
name: 'Users Service', | ||
endpoint: 'swagger.json', | ||
type: 'swagger' | ||
middlewares: [require('response-time')()], | ||
hooks: { | ||
rewriteHeaders (headers) { | ||
headers['post-processed'] = true | ||
return headers | ||
} | ||
} | ||
@@ -48,14 +52,2 @@ }, { | ||
}, { | ||
prefix: '/users/response-time', | ||
prefixRewrite: '', | ||
target: 'http://localhost:3000', | ||
middlewares: [require('response-time')()], | ||
hooks: { | ||
rewriteHeaders (headers) { | ||
headers['post-processed'] = true | ||
return headers | ||
} | ||
} | ||
}, { | ||
prefix: '/users/on-request-error', | ||
@@ -68,2 +60,10 @@ target: 'http://localhost:3000', | ||
} | ||
}, { | ||
prefix: '/users', | ||
target: 'http://localhost:3000', | ||
docs: { | ||
name: 'Users Service', | ||
endpoint: 'swagger.json', | ||
type: 'swagger' | ||
} | ||
}, | ||
@@ -70,0 +70,0 @@ { |
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
605
31315
302
+ Added0http@3.5.3(transitive)
+ Addedlru-cache@10.4.3(transitive)
+ Addedregexparam@1.3.03.0.0(transitive)
+ Addedrestana@4.9.9(transitive)
+ Addedtrouter@3.2.1(transitive)
- Removedfind-my-way@2.2.5(transitive)
- Removedrestana@3.4.2(transitive)
- Removedret@0.2.2(transitive)
- Removedsafe-regex2@2.0.0(transitive)
- Removedsemver-store@0.3.0(transitive)
Updatedrestana@^4.0.3