http-proxy-middleware icon indicating copy to clipboard operation
http-proxy-middleware copied to clipboard

Ability to support history fallback for single page application

Open jeremyrajan opened this issue 7 years ago • 2 comments

Expected behavior

Redirect to $URI index.html with current url when reloaded or refreshed.

Actual behavior

404, as express setup expects a url in the backend.

Setup

  • http-proxy-middleware: 0.17.4
  • server: express
  • other relevant modules - history-fallback-connect

proxy Setup

const FEProxy = proxy({ target: 'http://localhost:3000', proxyTimeout: 10000 });
const BEProxy = proxy({ target: 'http://localhost:9001', proxyTimeout: 10000 });

const app = express();

app.use('/edge', BEProxy);
app.use('/', FEProxy);

app.listen(8000, () => {
  console.log('Proxy started listening at 8000');
});

I tried to use, https://github.com/bripkens/connect-history-api-fallback but proxying stops working. Could you please advice on how I can setup history fallback with front end proxy setup using express setup above.

Thank you @chimurai for such an awesome lib!

Cheers, Jeremy

jeremyrajan avatar Aug 29 '17 06:08 jeremyrajan

@jeremyrajan Did you find a solution for this?

francoisromain avatar Jul 16 '20 13:07 francoisromain

pathRewrite: function (path, req) {
      if (path == "/" || path == "") {
        return "/index.html";
      }
      return path.replace("^/", "/");
    }

robbestad avatar Oct 16 '22 18:10 robbestad