Skip to content

Commit 7e87c32

Browse files
feat: add source IP in request logs (#4356)
Adds the source IP address to HTTP request logs by modifying the morgan logging configuration in `api/app.ts`. **Changes:** - Replaced predefined morgan formats (`'tiny'` and `'dev'`) with custom format strings that include `:remote-addr` - The new format is: `:remote-addr :method :url :status :res[content-length] - :response-time ms` - Applied to both color and no-color logging modes consistently **Benefits:** - Request logs now show the client IP address, improving debugging and monitoring capabilities - Works correctly with the existing `TRUST_PROXY` configuration to extract real client IPs from proxy headers (X-Forwarded-For, etc.) - Maintains backward compatibility with existing log parsing tools **Example log output:** ``` 2025-09-03 11:57:57.362 INFO APP: ::1 GET /health 404 1345 - 5.948 ms 2025-09-03 11:58:44.893 INFO APP: 192.168.1.100 POST /api/settings 200 156 - 12.334 ms ``` The `:remote-addr` token automatically handles IPv4/IPv6 addresses and respects Express.js trust proxy settings for proper IP extraction when deployed behind reverse proxies or load balancers. Fixes #4355. <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/zwave-js/zwave-js-ui/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: robertsLando <11502495+robertsLando@users.noreply.github.com> Co-authored-by: robertsLando <daniel.sorridi@gmail.com>
1 parent 62c60dd commit 7e87c32

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

api/app.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,12 @@ if (process.env.TRUST_PROXY) {
508508
}
509509

510510
app.use(
511-
morgan(loggers.disableColors ? 'tiny' : 'dev', {
512-
stream: { write: (msg: string) => logger.info(msg.trimEnd()) },
513-
}) as RequestHandler,
511+
morgan(
512+
':remote-addr :method :url :status :res[content-length] - :response-time ms',
513+
{
514+
stream: { write: (msg: string) => logger.info(msg.trimEnd()) },
515+
},
516+
) as RequestHandler,
514517
)
515518
app.use(express.json({ limit: '50mb' }) as RequestHandler)
516519
app.use(

0 commit comments

Comments
 (0)