connect-history-api-fallback icon indicating copy to clipboard operation
connect-history-api-fallback copied to clipboard

Is there a way to get the original path?

Open szimek opened this issue 7 years ago • 3 comments

I got the following code:

app.use(history());
app.get('/index.html', (req, res) => {
  ...
}

Is there any way to get the original path (before rewrite) inside the handler for /index.html path?

szimek avatar Feb 03 '17 12:02 szimek

No, this doesn't exist, but should be easy to add. Feel free to open a PR and I'll check it out.

bripkens avatar Feb 03 '17 13:02 bripkens

Is this not already accessible in with req.originalUrl ?(http://expressjs.com/en/api.html#req.originalUrl)

This example seems to work for me

const express = require("express");
var history = require("connect-history-api-fallback");

const app = express()

app.use(history({ verbose: true, index: '/' }));
app.get("/", function(req, res) {
  console.log("Responding from", req.originalUrl);
  res.send("Hello World");
});
app.listen(3000);

tiagogm avatar Jan 04 '18 15:01 tiagogm

This works with express, yes, but please note the different values compared to req.url (see the docs).

bripkens avatar Jan 07 '18 17:01 bripkens