Skip to content

Commit

Permalink
deps: bump to fastify 3.3.0 (#51)
Browse files Browse the repository at this point in the history
Changes in 3.2.1 to fastify resulted in a broken framework. The fastify
module added a `context` property to the request object, which we had
been decorating with a property by the same name. This commit bumps to
the latest 3.3.0 of fastify, and changes the property that we decorate
the request object with to `fcontext`. These changes are entirely
internal and do not affect the user function.
  • Loading branch information
lance committed Sep 2, 2020
1 parent 8e643e1 commit 81a94e1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 33 deletions.
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -26,9 +26,9 @@ function start(func, port, cb, options) {
const server = fastify({ logger: log });

// All incoming requests get a Context object
server.decorateRequest('context');
server.decorateRequest('fcontext');
server.addHook('preHandler', (req, reply, done) => {
req.context = new Context(req, reply);
req.fcontext = new Context(req, reply);
done();
});

Expand Down
2 changes: 1 addition & 1 deletion lib/event-handler.js
Expand Up @@ -15,7 +15,7 @@ function use(fastify, opts, done) {
if (request.isCloudEvent()) {
try {
const event = Receiver.accept(request.headers, request.body);
request.context.cloudevent = event;
request.fcontext.cloudevent = event;
} catch (err) {
if (err.message.startsWith('invalid spec version')) {
reply.code(406);
Expand Down
5 changes: 2 additions & 3 deletions lib/request-handler.js
Expand Up @@ -11,12 +11,11 @@ module.exports = function(fastify, opts, done) {
fastify.post('/', doPost);

async function doGet(request, reply) {
sendReply(reply, await invokeFunction(request.context, reply.log));
sendReply(reply, await invokeFunction(request.fcontext, reply.log));
}

async function doPost(request, reply) {
// request.context.body = request.body;
sendReply(reply, await invokeFunction(request.context, reply.log));
sendReply(reply, await invokeFunction(request.fcontext, reply.log));
}

eventHandler(fastify, null, done);
Expand Down
52 changes: 26 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -20,7 +20,7 @@
],
"dependencies": {
"cloudevents": "^3.1.0",
"fastify": "^3.2.0",
"fastify": "^3.3.0",
"overload-protection": "^1.1.0",
"qs": "^6.9.0"
},
Expand Down

0 comments on commit 81a94e1

Please sign in to comment.