-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2b4ee1f
commit bef71f8
Showing
15 changed files
with
480 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import winston from 'winston'; | ||
|
||
const customFormat = winston.format.printf(({ timestamp, level, message, correlationId, ...meta }) => { | ||
const metaString = Object.keys(meta).length ? JSON.stringify(meta) : ''; | ||
const requestIdString = correlationId ? ` requestId: ${correlationId}` : ''; | ||
return `[${timestamp}] ${level.toUpperCase()}: ${message} ${metaString}${requestIdString}`; | ||
}); | ||
|
||
const logger = winston.createLogger({ | ||
level: 'info', | ||
format: winston.format.combine( | ||
winston.format.timestamp({ | ||
format: 'YYYY-MM-DDTHH:mm:ss.sssZ', // Zulu time | ||
}), | ||
customFormat | ||
), | ||
transports: [ | ||
new winston.transports.Console({ | ||
stderrLevels: ['error'], | ||
}), | ||
// Uncomment this line to log to a file | ||
// new winston.transports.File({ filename: "app.log" }), | ||
], | ||
}); | ||
|
||
export default logger; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
|
||
// docs: https://nextjs.org/docs/app/building-your-application/routing/middleware | ||
export function middleware(request: NextRequest) { | ||
const correlationId = crypto.randomUUID(); // Generate a UUID | ||
|
||
const requestHeaders = new Headers(request.headers); | ||
requestHeaders.set('x-correlation-id', correlationId); | ||
|
||
const response = NextResponse.next({ | ||
request: { | ||
headers: requestHeaders, | ||
}, | ||
}); | ||
return response; | ||
} | ||
|
||
export const config = { | ||
matcher: '/api/v1/:path*', | ||
}; |
Oops, something went wrong.