You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
'use strict';constexpress=require('express');constrequestStats=require('request-stats');varapp=express();app.use('/api',(req,res,next)=>{console.log('req.url:',req.url);console.log('req.originalUrl:',req.originalUrl);res.end('OK');});varserver=app.listen(process.env.PORT||3000,()=>{console.log('Listening on port %d',server.address().port);});requestStats(server,(stats)=>{console.log('stats.req.path:',stats.req.path);});
Hmm it seems that express is modifying req.url property 😞 Not the best move by express IMHO, so I'm not really sure if there's much I can do about it.
I could of course use req.originalUrl || req.url, but that seems oddly specific for this use-case. And I hate hacks like that. Preferably I'd like to make this more low-level.
How would you feel about just exposing the original request object, so that you can do stats.req.raw.originalUrl your self?
Yes, this would be useful as the raw request may contain additional properties of statistical value.
To be consistent, you can expose also the raw response object.
main.js
The text was updated successfully, but these errors were encountered: