0
Good afternoon guys, I made an API with Node and I consumed it with React, in development environment, works OK because I start one independent of the other, but in production I’m trying to deliver the static files compiled by React to Node, are 3 files. HTML, CSS and JS. HTML is being delivered perfectly, however JS and CSS do not seem to be Oks.
In this case, the HTML is being delivered because the title and icon are working, but the screen turns white and in the console appears the following message: "Failed to load with source "http://biodinamicahc.com.br/app.js"
In case, I’m handing over the public folder of the second form:
if (process.env.PRODUCTION) {
app.set('public', path.resolve(__dirname, '../../public'));
app.use(express.static(app.get('public')));
}
For when the "/" route is accessed, it plays the other files together.
server.get('/', (req, res) => {
if (process.env.PRODUCTION) {
res.sendFile(path.resolve(__dirname, '../../../public/index.html'));
} else {
res.status(500).send({
message: 'API rodando em ambiente de desenvolvimento!'
})
}
});
I tried to play the static JS and CSS files together in "res.sendFile", but it didn’t work, the message continued. Would anyone know what to say?
Thank you!