I have build a project started with create-react-app. I'm trying it to serve it with express. It works, but when I try to go to other routes, these routes are not working and my React app page is the only one thing that showing up. Could you explain me why please ? Here is my code.
const express = require('express');
const path = require('path');
const app = express();
const router = express.Router();
app.use(express.static(path.join(__dirname, 'build')));
app.use('/', router);
router.get('/api', (req, res) => {
res.send("API endpoints! ;)")
});
router.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.listen(8080, () => {
console.log('Listening on 8080');
})
I have tried the solution there `express.static()` keeps routing my files from the route but it doesn't work.