Skip to content

Commit 4c902aa

Browse files
authored
Merge pull request #1 from fastify/override-body-parser
Override the default json parser
2 parents c0b0f7c + 6627b9a commit 4c902aa

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

example.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ async function startProxy (upstream) {
3333
})
3434

3535
await server.listen(3000)
36+
return server
3637
}
3738

3839
async function run () {

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)