1
+ import type { FastifyInstance , FastifyReply , FastifyRequest } from 'fastify' ;
1
2
import fastify from 'fastify' ;
2
3
import { fastifyConfig , replyFromConfig } from './config/fastify.config' ;
3
- import type { FastifyInstance , FastifyReply , FastifyRequest } from 'fastify' ;
4
4
import type { Logger } from 'common/logger/createFastifyLogger' ;
5
5
import { createFastifyLogger } from 'common/logger/createFastifyLogger' ;
6
6
import { createErrorLog } from 'common/error/system.error' ;
@@ -17,6 +17,10 @@ interface FastifyServer {
17
17
stop : ( server : FastifyInstance , logger : Logger ) => Promise < void > ;
18
18
}
19
19
20
+ export interface Locals {
21
+ originalContentType ?: string ;
22
+ }
23
+
20
24
export const fastifyServer : FastifyServer = {
21
25
listen : ( ) => startFastifyServer ( ) ,
22
26
stop : ( server : FastifyInstance , logger : Logger ) => stopFastifyServer ( server , logger ) ,
@@ -79,6 +83,11 @@ const initialize = (server: FastifyInstance, logger: Logger) => {
79
83
80
84
const addPlugins = ( server : FastifyInstance ) => {
81
85
server . register ( replyFrom , replyFromConfig ) ;
86
+ server . addHook ( 'preHandler' , async ( request ) => {
87
+ ( request as any ) . locals = {
88
+ originalContentType : request . headers [ 'content-type' ] ,
89
+ } ;
90
+ } ) ;
82
91
} ;
83
92
84
93
const addRouters = ( server : FastifyInstance , logger : Logger ) => {
0 commit comments