Answer the question
In order to leave comments, you need to log in
Why are styles and images not loading in Heroku?
Made a small application on express.js. The application has a small form that sends data to the right place. Then uploaded to heroku. But there was a problem, pictures from the public folder were not loaded, custom styles from there also do not work. Bootstrap works with cdn.
I tried to change the paths, made absolute and relative ones - it didn’t help, it only affects the local display.
I was looking for a solution to the problem in Google, there are a lot of such questions on the stack, but people there suffer from RoR, but I don’t understand what it’s about at all, since I work with js.
In general, somewhere there is a solution, but where is unknown.
Problem solved. .gitignore contained a lot of "excess"
Answer the question
In order to leave comments, you need to log in
app.use(express.static('/public'));
or wrote something like that?
again, you can collect the path through path.resolve, otherwise Linux is in the same place, and on the local machine for any windows
I have something on Herok, such code in the main server.js distributes everything as it should
if (process.env.NODE_ENV === 'production') {
// Set static folder
app.use(express.static('client/build')); // это собранный проект реакт и его "public"
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
// это наверно неактуально, но так собирается правильный путь через path.resolve
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question