Created
October 18, 2018 08:16
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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