fast-gateway
Advanced tools
Comparing version 1.1.2 to 1.2.0
18
index.js
const fastProxy = require('fast-proxy') | ||
const restana = require('restana') | ||
const pump = require('pump') | ||
const toArray = require('stream-to-array') | ||
@@ -27,2 +29,3 @@ const gateway = (opts) => { | ||
route.hooks.onRequest = route.hooks.onRequest || onRequestNoOp | ||
route.hooks.onResponse = route.hooks.onResponse || onResponse | ||
@@ -56,3 +59,18 @@ // populating pathRegex if missing | ||
const onRequestNoOp = (req, res) => { } | ||
const onResponse = async (req, res, stream) => { | ||
if (!res.hasHeader('content-length')) { | ||
try { | ||
const resBuffer = Buffer.concat(await toArray(stream)) | ||
res.statusCode = stream.statusCode | ||
res.setHeader('content-length', '' + Buffer.byteLength(resBuffer)) | ||
res.end(resBuffer) | ||
} catch (err) { | ||
res.send(err) | ||
} | ||
} else { | ||
res.statusCode = stream.statusCode | ||
pump(stream, res) | ||
} | ||
} | ||
module.exports = gateway |
{ | ||
"name": "fast-gateway", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "A Node.js API Gateway for the masses!", | ||
@@ -31,3 +31,4 @@ "main": "index.js", | ||
"http-cache-middleware": "^1.0.0", | ||
"restana": "^3.1.1" | ||
"restana": "^3.1.1", | ||
"stream-to-array": "^2.3.0" | ||
}, | ||
@@ -34,0 +35,0 @@ "devDependencies": { |
@@ -233,3 +233,3 @@ /* global describe, it, setImmediate */ | ||
await request(gateway) | ||
.post('/users/find') | ||
.post('/users/info') | ||
.expect(404) | ||
@@ -236,0 +236,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
21351
397
4
+ Addedstream-to-array@^2.3.0
+ Addedany-promise@1.3.0(transitive)
+ Addedstream-to-array@2.3.0(transitive)