Skip to content

Commit

Permalink
Merge pull request #258 from podium-lib/run_layout_process_earlier
Browse files Browse the repository at this point in the history
fix: run podium processes earlier in Fastify lifecycle
  • Loading branch information
digitalsadhu authored Jun 3, 2024
2 parents 3585af1 + 6e9c7a7 commit 9ba4f45
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lib/layout-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,17 @@ const podiumLayoutFastifyPlugin = (fastify, layout, done) => {
fastify.addHook('onRequest', async (request, reply) => {
// namespace
reply.app = reply.app || {};
// used to hold the HttpIncoming object
reply.app.podium = reply.app.podium || {};
// used to pass additional values to HttpIncoming
reply.app.params = reply.app.params || {};
});

// Run parsers on request and store state object on reply.app.podium
fastify.addHook('preHandler', async (request, reply) => {
const incoming = new HttpIncoming(
// used to hold the HttpIncoming object
reply.app.podium = new HttpIncoming(
request.raw,
reply.raw,
reply.app.params,
);
reply.app.podium = await layout.process(incoming, { proxy: false });
reply.app.podium = await layout.process(reply.app.podium, {
proxy: false,
});
});

// Decorate response with .podiumSend() method
Expand Down

0 comments on commit 9ba4f45

Please sign in to comment.