fastify-http-proxy
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -26,2 +26,3 @@ /// <reference types="node" /> | ||
http2?: boolean; | ||
proxyPayloads?: boolean; | ||
preHandler?: ( | ||
@@ -28,0 +29,0 @@ request: FastifyRequest< |
@@ -25,4 +25,6 @@ 'use strict' | ||
fastify.addContentTypeParser('application/json', bodyParser) | ||
fastify.addContentTypeParser('*', bodyParser) | ||
if (opts.proxyPayloads !== false) { | ||
fastify.addContentTypeParser('application/json', bodyParser) | ||
fastify.addContentTypeParser('*', bodyParser) | ||
} | ||
@@ -29,0 +31,0 @@ function rewriteHeaders (headers) { |
{ | ||
"name": "fastify-http-proxy", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "proxy http requests, for Fastify", | ||
@@ -33,3 +33,3 @@ "main": "index.js", | ||
"fastify": "^2.0.0", | ||
"got": "^10.0.0", | ||
"got": "^10.6.0", | ||
"http-errors": "^1.7.1", | ||
@@ -36,0 +36,0 @@ "http-proxy": "^1.17.0", |
@@ -97,2 +97,15 @@ # fastify-http-proxy | ||
### proxyPayloads | ||
When this option is `false`, you will be able to access the body but it will also disable direct pass through of the payload. As a result, it is left up to the implementation to properly parse and proxy the payload correctly. | ||
For example, if you are expecting a payload of type `application/xml`, then you would have to add a parser for it like so: | ||
```javascript | ||
fastify.addContentTypeParser('application/xml', (req, done) => { | ||
const parsedBody = parsingCode(req) | ||
done(null, parsedBody) | ||
}) | ||
``` | ||
### config | ||
@@ -99,0 +112,0 @@ |
@@ -114,2 +114,26 @@ 'use strict' | ||
test('skip proxying the incoming payload', async t => { | ||
const server = Fastify() | ||
server.register(proxy, { | ||
upstream: `http://localhost:${origin.server.address().port}`, | ||
proxyPayloads: false, | ||
preHandler (request, reply, next) { | ||
t.deepEqual(request.body, { hello: 'world' }) | ||
next() | ||
} | ||
}) | ||
await server.listen(0) | ||
t.tearDown(server.close.bind(server)) | ||
await got( | ||
`http://localhost:${server.server.address().port}/this-has-data`, | ||
{ | ||
method: 'POST', | ||
json: { hello: 'world' }, | ||
responseType: 'json' | ||
} | ||
) | ||
}) | ||
test('preHandler', async t => { | ||
@@ -116,0 +140,0 @@ const server = Fastify() |
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
22230
527
144