expressjs / expressjs/express

Add originalRoute like originalUrl

Open
#2,501 30 comments 5 reactions 0 assignees View on GitHub
discuss module:router
Dominant language
JavaScript
Stars
69.5k
Forks
25k
Avg merge
4d 20h
Merged PRs (30d)
9

Description

In a request we can get the originalUrl, which is the complete URL for the request after it has travelled through nested routes.

But I think an originalRoute would be at least as usefull, especially for request logging.

I don't think it should be that difficult to add.

Currently I've made a simple hack to accomplish this, but I rather see it built-in.

```
var _ = require('lodash');
var express = require('express');
var Router = express.Router;
var Router_process_params = Router.process_params;

Router.process_params = function (layer, called, req, res, done) {
req.originalRoute = (req.originalRoute || '') + (req.route && req.route.path || layer.path || '');
return Router_process_params.apply(this, _.toArray(arguments));
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.