diff --git a/Earthfile b/Earthfile index 947a65fe..98fc0248 100644 --- a/Earthfile +++ b/Earthfile @@ -121,7 +121,6 @@ docker-image: ENV APP_DATABASE_URL="file:$APP_DATABASE_PATH" ENV CACHE_DATABASE_FILENAME="cache.db" ENV CACHE_DATABASE_PATH="/data/$CACHE_DATABASE_FILENAME" - ENV HTTP_LOG_PATH="/data/http-log.jsonl" ENV INTERNAL_PORT="8080" ENV PORT="8081" diff --git a/app/utils/env.server.ts b/app/utils/env.server.ts index 81394c5f..02d30e94 100644 --- a/app/utils/env.server.ts +++ b/app/utils/env.server.ts @@ -5,7 +5,7 @@ const schema = z.object({ APP_DATABASE_PATH: z.string(), APP_DATABASE_URL: z.string(), GB_DATABASE_PATH: z.string(), - HTTP_LOG_PATH: z.string(), + HTTP_LOG_PATH: z.optional(z.string()), SESSION_SECRET: z.string(), INTERNAL_COMMAND_TOKEN: z.string(), HONEYPOT_SECRET: z.string(), diff --git a/server/index.ts b/server/index.ts index 34d5e474..de640885 100644 --- a/server/index.ts +++ b/server/index.ts @@ -96,27 +96,29 @@ app.use( app.use(express.static('public', { maxAge: '1h' })) const httpLogPath = process.env.HTTP_LOG_PATH -const logger = pino(pino.destination(httpLogPath)) - -// Use pino-http middleware with custom logging -app.use( - pinoHttp({ - logger, - serializers: { - // https://github.com/pinojs/pino-http/issues/5#issuecomment-955748053 - res: pino.stdSerializers.wrapResponseSerializer((res: any) => { - return { - statusCode: res.raw.statusCode, - // Allowlist useful headers - headers: { - 'content-type': res.raw.headers['content-type'], - 'content-length': res.raw.headers['content-length'], - }, - } - }), - }, - }), -) +if (httpLogPath !== undefined) { + const logger = pino(pino.destination(httpLogPath)) + + // Use pino-http middleware with custom logging + app.use( + pinoHttp({ + logger, + serializers: { + // https://github.com/pinojs/pino-http/issues/5#issuecomment-955748053 + res: pino.stdSerializers.wrapResponseSerializer((res: any) => { + return { + statusCode: res.raw.statusCode, + // Allowlist useful headers + headers: { + 'content-type': res.raw.headers['content-type'], + 'content-length': res.raw.headers['content-length'], + }, + } + }), + }, + }), + ) +} app.get(['/build/*', '/img/*', '/fonts/*', '/favicons/*'], (req, res) => { // if we made it past the express.static for these, then we're missing something.