Skip to content

Instantly share code, notes, and snippets.

@modestotech
Created October 18, 2018 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save modestotech/a2c5527c2a2d0e5d6eb044a417e2284c to your computer and use it in GitHub Desktop.
Save modestotech/a2c5527c2a2d0e5d6eb044a417e2284c to your computer and use it in GitHub Desktop.
There is a problem with webpack-dev-server that makes so that all calls that are not root (/) goes to the backend and produces a 404 error. The solution is to redirect all calls to index.html.
// The snippet below achieves in a Node backend what
// "historyApiFallback: true" flag achieves on a webpack-dev-server environment.
// By redirecting all requests to index.html, the routing contained in the frontend app
// takes care of redirecting to the right place
const viewRouter = require('./routes/view');
app.use('/',viewRouter);
router.route('/*')
.get((req,res)=>res.sendFile(path.resolve(__dirname, '../dist', 'index.html')));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment