Skip to content

Commit a5c852d

Browse files
committed
Override the default json parser
1 parent c0b0f7c commit a5c852d

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ module.exports = async function (fastify, opts) {
1313
base: opts.upstream
1414
})
1515

16-
fastify.addContentTypeParser('*', function (req, done) {
16+
fastify.addContentTypeParser('application/json', bodyParser)
17+
fastify.addContentTypeParser('*', bodyParser)
18+
19+
function bodyParser (req, done) {
1720
done(null, req)
18-
})
21+
}
1922

2023
fastify.all('/', { beforeHandler }, reply)
2124
fastify.all('/*', { beforeHandler }, reply)
2225

2326
function reply (request, reply) {
24-
const dest = request.req.url.replace(this.basePath, '')
27+
var dest = request.raw.url.replace(this.basePath, '')
2528
reply.from(dest)
2629
}
2730
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
"homepage": "https://github.com/fastify/fastify-http-proxy#readme",
2424
"devDependencies": {
25-
"fastify": "^1.0.0-rc.1",
25+
"fastify": "^1.0.0-rc.2",
2626
"got": "^8.0.3",
2727
"http-errors": "^1.6.2",
2828
"make-promises-safe": "^1.1.0",

0 commit comments

Comments
 (0)