So I am just trying to serve static files (a built React app) to localhost:3030 via:
const express = require('express');
const path = require('path');
const app = express();
app.use(
express.static(path.join(__dirname, '../client/build'))
);
app.listen(3030);
The structure of the target folder is as follows
- static/
- js/
- 000.hash.chunk.js
- 000.hash.chunk.js.map
- main.hash2.js
- main.hash2.js.map
- main.hash2.js.LICENSE.txt
- css/
- main.hash3.css
- main.hash3.css.map
- index.html
Inside index.html there is a defer script element that has a src of /static/js/main.hash2.js and a link element that has an href of static/css/main.hash3.css.
Accessing localhost:3030 shows me index.html, as expected, but it cannot load the javascript or CSS, it returns a 404 error, and Cannot GET /static/js/main.hash2.js/ if accessed in the browser. When trying to access /static/js/main.hash2.js.LICENSE.txt, however, the text file displays as usual. I've tried renaming the CSS and JS files to something like test.js/test.css and changing the src and href attributes on the elements and this fixes this problem entirely, but it's a pain to do.
I've tried adding {dotfiles: 'allow'} to express.static() just in case that had anything to do with it, but it did not work.
Any help would be much appreciated.