April 2020
Intermediate to advanced
716 pages
18h 55m
English
To ensure that the Express server properly handles the requests to static files such as CSS files, images, or the bundled client-side JS, we will configure it so that it serves static files from the dist folder by adding the following configuration in express.js.
mern-skeleton/server/express.js:
import path from 'path'const CURRENT_WORKING_DIR = process.cwd()app.use('/dist', express.static(path.join(CURRENT_WORKING_DIR, 'dist')))
With this configuration in place, when the Express app receives a request at a route starting with /dist, it will know to look for the requested static resource in the dist folder before returning the resource in the response. Now, we can load the bundled files from the dist folder ...