Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stats.req.path may not be the real path requested #4

Closed
dotchev opened this issue Nov 9, 2016 · 3 comments
Closed

stats.req.path may not be the real path requested #4

dotchev opened this issue Nov 9, 2016 · 3 comments

Comments

@dotchev
Copy link

dotchev commented Nov 9, 2016

main.js

'use strict';

const express = require('express');
const requestStats = require('request-stats');

var app = express();

app.use('/api', (req, res, next) => {
  console.log('req.url:', req.url);
  console.log('req.originalUrl:', req.originalUrl);
  res.end('OK');
});

var server = 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);
});
$ node main.js 
Listening on port 3000
$ curl http://localhost:3000/api/user
req.url: /user
req.originalUrl: /api/user
stats.req.path: /user
@watson
Copy link
Owner

watson commented Nov 10, 2016

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?

@dotchev
Copy link
Author

dotchev commented Nov 10, 2016

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.

@watson watson closed this as completed in 515e92b Nov 24, 2016
@watson
Copy link
Owner

watson commented Nov 24, 2016

@dotchev this have now been released in v2.0.0 on npm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants