Full-Stack React Projects
上QQ阅读APP看书,第一时间看更新

Serving static files with Express

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 to serve 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')))