Skip to content

Commit

Permalink
fix: Explicit return types
Browse files Browse the repository at this point in the history
  • Loading branch information
franky47 committed May 7, 2024
1 parent 93ce089 commit 18b877d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FastifyReply, FastifyRequest } from 'fastify'
import type { FastifyServerOptions } from 'fastify'
import crypto from 'node:crypto'
import pino from 'pino'
import redactEnv from 'redact-env'
Expand All @@ -23,7 +23,7 @@ export function getLoggerOptions({
name,
redactEnv = [],
redactLogPaths = []
}: Options) {
}: Options): FastifyServerOptions['logger'] {
// todo: Move env redaction to a Pino v7+ Transport
return {
level:
Expand All @@ -48,25 +48,27 @@ export function getLoggerOptions({
commit: process.env.COMMIT_ID?.slice(0, 8)
},
serializers: {
req(req: FastifyRequest) {
req(req) {
return {
method: req.method,
url: req.url,
headers: req.headers
}
},
res(res: FastifyReply) {
res(res) {
return {
statusCode: res.statusCode,
headers: res.getHeaders()
headers: res.getHeaders?.() ?? {}
}
}
}
}
}

export const makeReqIdGenerator = (defaultSalt: string = randomID()) =>
function genReqId(req: FastifyRequest): string {
export const makeReqIdGenerator = (
defaultSalt: string = randomID()
): FastifyServerOptions['genReqId'] =>
function genReqId(req) {
let ipAddress: string = ''
const xForwardedFor = req.headers['x-forwarded-for']
if (xForwardedFor) {
Expand Down

0 comments on commit 18b877d

Please sign in to comment.