1+ import type { FastifyInstance , FastifyReply , FastifyRequest } from 'fastify' ;
12import fastify from 'fastify' ;
23import { fastifyConfig , replyFromConfig } from './config/fastify.config' ;
3- import type { FastifyInstance , FastifyReply , FastifyRequest } from 'fastify' ;
44import type { Logger } from 'common/logger/createFastifyLogger' ;
55import { createFastifyLogger } from 'common/logger/createFastifyLogger' ;
66import { createErrorLog } from 'common/error/system.error' ;
@@ -17,6 +17,10 @@ interface FastifyServer {
1717 stop : ( server : FastifyInstance , logger : Logger ) => Promise < void > ;
1818}
1919
20+ export interface Locals {
21+ originalContentType ?: string ;
22+ }
23+
2024export const fastifyServer : FastifyServer = {
2125 listen : ( ) => startFastifyServer ( ) ,
2226 stop : ( server : FastifyInstance , logger : Logger ) => stopFastifyServer ( server , logger ) ,
@@ -79,6 +83,11 @@ const initialize = (server: FastifyInstance, logger: Logger) => {
7983
8084const addPlugins = ( server : FastifyInstance ) => {
8185 server . register ( replyFrom , replyFromConfig ) ;
86+ server . addHook ( 'preHandler' , async ( request ) => {
87+ ( request as any ) . locals = {
88+ originalContentType : request . headers [ 'content-type' ] ,
89+ } ;
90+ } ) ;
8291} ;
8392
8493const addRouters = ( server : FastifyInstance , logger : Logger ) => {
0 commit comments