keithweaver / MERN-boilerplate

MERN stack project boilerplate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue in running this boilerplate in Production.

lastgiven opened this issue · comments

Hi Keith.

Thanks for the boilerplate. Saved me a lot of time but when I took it live I had an issue where if you browse to any of the pages except for the home page a white screen is returner.

app.get('*', function (req, res) { res.sendFile(path.resolve(__dirname, '../dist/index.html')); res.end(); });
If you remove the res.end() piece it will resolve the issue. I have updated my solution to be:
app.get('*', function (req, res) { res.sendFile(path.resolve(__dirname, '../dist/index.html'), (err) => { if(err){ console.log(err); } res.end() }); });

This is just a note for anyone else that is having the same issue.

I think the reason this happens is because whilst the server is busy processing the file that needs to be returned the res.end(); call cuts the response in the middle and nothing is returned.

Thank you so much for putting your solution on here, ive been trying to figure this out forever, i really should have looked at these issues first