Skip to content

Commit

Permalink
fix(server): more accurate requestPath
Browse files Browse the repository at this point in the history
  • Loading branch information
fabis94 committed Feb 12, 2024
1 parent 0e7b2a0 commit d836b64
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/server/logging/expressLogging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export const LoggingExpressMiddleware = HttpLogger({
customSuccessObject(req, res, val: Record<string, unknown>) {
const isCompleted = !req.readableAborted && res.writableEnded
const requestStatus = isCompleted ? 'completed' : 'aborted'
const requestPath = req.url?.split('?')[0] || 'unknown'
const requestPath =
(get(req, 'originalUrl') || get(req, 'url') || '').split('?')[0] || 'unknown'
const country = req.headers['cf-ipcountry'] as Optional<string>

return {
Expand All @@ -60,7 +61,8 @@ export const LoggingExpressMiddleware = HttpLogger({
},
customErrorObject(req, res, err, val: Record<string, unknown>) {
const requestStatus = 'failed'
const requestPath = req.url?.split('?')[0] || 'unknown'
const requestPath =
(get(req, 'originalUrl') || get(req, 'url') || '').split('?')[0] || 'unknown'
const country = req.headers['cf-ipcountry'] as Optional<string>

return {
Expand All @@ -79,7 +81,7 @@ export const LoggingExpressMiddleware = HttpLogger({
return {
id: req.raw.id,
method: req.raw.method,
path: req.raw.url?.split('?')[0], // Remove query params which might be sensitive
path: (get(req.raw, 'originalUrl') || get(req.raw, 'url') || '').split('?')[0],
// Allowlist useful headers
headers: Object.fromEntries(
Object.entries(req.raw.headers).filter(
Expand Down

0 comments on commit d836b64

Please sign in to comment.