-
-
Notifications
You must be signed in to change notification settings - Fork 9
Closed
fastify/fastify-request-context
#12Description
import fastify from 'fastify';
const { fastifyRequestContextPlugin } = require('fastify-request-context');
const server = fastify({
logger: true
});
const preValidationFn = (req, reply, done): any => {
req.requestContext.set('hello', 'hello world');
console.log(req.requestContext.get('hello'));
done();
};
const handlerFn = (req, reply): any => {
console.log(req.requestContext.get('hello'));
reply.send('hello world');
};
server.route({
url: '/test',
method: ['GET', 'POST'],
preValidation: preValidationFn,
handler: handlerFn
});
server.register(fastifyRequestContextPlugin);
console.log('Starting fastify Typescript server ');
server.listen(8085, '0.0.0.0', (err, address): void => {
if (err) {
console.warn(err);
process.exit(1);
}
console.info(`Server listening at ${address}`);
});
process.on('uncaughtException', error => {
console.error(error);
});
process.on('unhandledRejection', error => {
console.error(error);
});
This is my fastify server written in typescript while using the fastify-request-context plugin I am able to access the context of fastify request when I am requesting the resource using the GET method, But I am not able to access the context of fastify request if I am requesting the resource using POST method
This is the stackoverflow link
Metadata
Metadata
Assignees
Labels
No labels