I have built react-ssr with webpack, express and react. I build react files in different folder called build. Than I bundle my server side. Than I want to serve the files inside build/ folder. But it does not work.
https://something.com/static/css/main.chunk.css
https://something.com/static/js/main.chunk.js
These urls returns with 404
https://something.com/build/static/css/main.chunk.css
https://something.com/build/static/js/main.chunk.js
These urls work.
/server/index.js
I tried two express static use function.
app.use('/static',express.static('../build/static'));
app.use(express.static(build'));
None of these worked. As you see below I am bundling server side into server_build/index.js. And I am calling node server_build/index.js which causes build/ folder not in the root.
My file structure is something like this.
build
|_static ==> This is where I got 404
|_js
|_main.chunk.js
|_main.chunk0.js
|_css
|_main.chunk.css
|_main.chunk0.css
server_build
|_index.js ==> This is bundled server side express code.
|_main.css
server
|_index.js ==> This is where my unbundled index js.
I am probably missing something here but it just does not work. This was working in my Macbook localhost, now It does not work on my Linux dedicated server. Whether there is a path issue or node execution root issue. Please help
question from:
https://stackoverflow.com/questions/65918252/express-does-not-serve-static-files 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…