score:2

Accepted answer

having looked at your repo for server.js you are sending all your traffic that hits your server (even your own api requests) to your front end.

first make sure your server-side routes start with something distinguishable such as

app.get('/api/*',(req,res)=>/*somecode*/)

this is because your server will confuse something like '/login' if it is also a route in your front end and will only end up serveing one or the other depending on when they are defined.

then update your server.js to match this and it should work:

//api requests handled first
require('./routes')(app);

//non api requests in production
if (process.env.node_env === 'production') {
    app.use([someproductionmiddleware()])
    // express will serve up production assets i.e. main.js
    app.use(express.static('client/build'));
    // if express doesn't recognize route serve index.html
    const path = require('path');
    app.get('*', (req, res) => {
        res.sendfile(
            path.resolve(__dirname, 'client', 'build', 'index.html')
        );
    });
}

Related Query

More Query from same tag