Skip to content
This repository was archived by the owner on Jan 8, 2023. It is now read-only.

Conversation

@Mnwa
Copy link

@Mnwa Mnwa commented Dec 17, 2019

Hey! In my project I need to use router mask instead originalUrl param. I will add support it with optional flag.

Copy link
Owner

@joao-fontenele joao-fontenele left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see some problems with this implementation

  • if a route doesn't have a handler, it will not enter the middleware, and will therefore not be measured, depending on the application it's important to know if a client is eventually calling a route without a handler
  • if the express app uses express.Router the parent routing will not be part of req.path.route, so the metrics will have the wrong label

I agree that req.route.path have a nicer formatting and maybe it should have been the default, but it doesn't seem to work for nested routers.

Opinions or better ideas to handle these cases are welcome

Copy link
Owner

@joao-fontenele joao-fontenele left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to exemplify the matter with nested routers here's a minimal snippet

const express = require('express');

const app = express();
const router = new express.Router({ mergeParams: true });

router.get('/nested/:id', (req, res) => {
  console.log('GET /internal/some/:id');
  console.log('req.originalUrl', req.originalUrl); // will log `/parent/nested/1`
  console.log('req.route.path', req.route.path); // will log `/nested/:id`
  res.sendStatus(200);
});

app.use('/parent', router);


const PORT = 9001;
app.listen(PORT, () => {
  console.log(`Example api is listening on http://localhost:${PORT}`);
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants