bripkens / connect-history-api-fallback

Fallback to index.html for applications that are using the HTML 5 history API
MIT License
1.83k stars 142 forks source link

Is there a way to get the original path? #34

Open szimek opened 7 years ago

szimek commented 7 years ago

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?

bripkens commented 7 years ago

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

tiagogm commented 6 years ago

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);
bripkens commented 6 years ago

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