File tree Expand file tree Collapse file tree 3 files changed +37
-7
lines changed
Expand file tree Collapse file tree 3 files changed +37
-7
lines changed Original file line number Diff line number Diff line change 66} from "fastify-type-provider-zod" ;
77import { z } from "zod/v4" ;
88
9+ import config , { DurationGranularity } from "./config" ;
910import headersRoute from "./routes/headers" ;
1011import healthCheckRoute from "./routes/health" ;
1112import codesRoute from "./routes/codes" ;
@@ -25,8 +26,11 @@ const createServer = (opts: FastifyServerOptions = {}) => {
2526
2627 // add custom properties to keep track of timings
2728 fastify . decorateReply ( "startTime" , 0 ) ;
28- // fastify.decorateReply("getTime", () => performance.now());
29- fastify . decorateReply ( "getTime" , ( ) => Date . now ( ) ) ;
29+ fastify . decorateReply ( "getTime" , ( ) =>
30+ config . server . durationGranularity === DurationGranularity . Default
31+ ? Date . now ( )
32+ : performance . now ( )
33+ ) ;
3034
3135 // custom logging using hooks
3236 fastify . addHook ( "onRequest" , ( req , res , done ) => {
Original file line number Diff line number Diff line change 1+ import env from "./env" ;
2+
3+ const HOST : string = env . HOST ;
4+ const PORT : number = env . PORT ;
5+
6+ export enum DurationGranularity {
7+ Default = "default" ,
8+ High = "high" ,
9+ }
10+ type Config = {
11+ server : {
12+ host : string ;
13+ port : number ;
14+ durationGranularity : DurationGranularity ;
15+ } ;
16+ } ;
17+
18+ const config : Config = {
19+ server : {
20+ host : HOST ,
21+ port : PORT ,
22+ durationGranularity : DurationGranularity . Default ,
23+ } ,
24+ } ;
25+
26+ export default config ;
Original file line number Diff line number Diff line change 11// import EventEmitter from "events";
22import createServer from "./app" ;
3- import env from "./env" ;
4-
5- const HOST : string = env . HOST ;
6- const PORT : number = env . PORT ;
3+ import config from "./config" ;
74
85const start = async ( ) => {
96 const fastify = createServer ( {
@@ -67,7 +64,10 @@ const start = async () => {
6764 // START ---
6865
6966 try {
70- await fastify . listen ( { port : PORT , host : HOST } ) ;
67+ await fastify . listen ( {
68+ port : config . server . port ,
69+ host : config . server . host ,
70+ } ) ;
7171 } catch ( err ) {
7272 throw err ;
7373 }
You can’t perform that action at this time.
0 commit comments