Conversation
Signed-off-by: Thomas Kientz <10157845+ThomasKientz@users.noreply.github.com>
|
the tests are not happy |
gurgunday
left a comment
There was a problem hiding this comment.
Decorate that new assignment to req please
Signed-off-by: Thomas Kientz <10157845+ThomasKientz@users.noreply.github.com>
Signed-off-by: Thomas Kientz <10157845+ThomasKientz@users.noreply.github.com>
@Uzlopak don't really understand why it's failing, looks good but return exit code 1 |
|
The test coverage is Not 100% |
There was a problem hiding this comment.
Where is payload.rawBody comes from?
I don't like the current idea to support one serverless environment and adding extra branching.
Instead one should provide a plugin that dedicated for the serverless environment and add all the necessary patching to match how Node.js works.
|
Well the problem is, that gcf is a glorified express router. So they preparse the body so that you dont have to. You get the body stream in rawBody. So maybe we need, like you suggest, a plugin which basically removes the default content type parsers and just assigns rawbody to body?! |
|
What's comes my mind is something like? function gcp(fastify) {
// add pass through content-type parser
fastify.addContentTypeParser('application/json', {}, (req, body, done) => {
done(null, body.body);
});
// add stream transform for multipart when neccessary
if (fastify.hasContentTypeParser('multipart/form-data')) {
fastify.addHook('preParsing', function(request, reply, payload, done) {
if(request.headers['content-type'].startsWith('multipart/form-data')) {
// we override the `.pipe` method and return rawBody as new payload
const pipe = request.raw.pipe
request.raw.pipe = function(stream) {
Readable.from([rawBody]).pipe(stream)
}
request.raw.originalPipe = pipe
done(null, payload.rawBody)
} else {
done(null, payload)
}
})
}
} |
|
Should I pursue the current implementation of this pull request and add test coverage? @Uzlopak |
Currently we can't use this plugin with serverless GCP (or Firebase).
As explained here fastify/fastify#946 (comment) and in the doc for firebase, we need to use
req.rawBodyin order to parse files from multipart.