Open FranciscoKnebel opened 2 years ago
I am currently having the same problem. Have you solved this issue or found any other solutions?
According to the docs - Serve It needs a "process file" with specified configuration.
I found the docs for EcoSystem Files
My ecosystem.config.js
file looks like:
module.exports = {
apps: [{
name: "dc-static",
script: "serve",
env: {
PM2_SERVE_PATH: "./build",
PM2_SERVE_PORT: 3003,
PM2_SERVE_SPA: true,
PM2_SERVE_HOMEPAGE: "./build/index.html"
}
}],
}
I tried pm2 start ecosystem.config.js
which gives me the following correctly, but still doesn't resolve the refresh issue.
[PM2][WARN] Applications dc-static not running, starting...
[PM2] App [dc-static] launched (1 instances)
┌────┬──────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├────┼──────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0 │ dc-static │ default │ 5.3.0 │ fork │ 40219 │ 0s │ 0 │ online │ 0% │ 1.5mb │ kes… │ disabled │
└────┴──────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
[PM2][WARN] Current process list is not synchronized with saved list. App static-page-server-3001 differs. Type 'pm2 save' to synchronize.
What's going wrong?
PM2 serve doesn't work for serving applications in subfolders, as in "example.com/app1". Example of this is apps that require a basename/relative path (https://create-react-app.dev/docs/deployment/#building-for-relative-paths). --spa makes the subroutes return the index.html, instead of the values in the subfolder. So the index.html, favicon, manifest.json, that are on the base folder are served, but anything in subdirectories (like a static/js/*.js) return index.html
How could we reproduce this issue?
PUBLIC_URL="/app1" npm run build
to set the base path for the build process.Will show a blank page, and the files in subfolders (like static/js/*) will return index.html
Supporting information
Couldn't find a way to set a basename for Serve, so I believe the script only expects to be hosting at root /. Perhaps adding a new parameter that prepends the basename is a possible fix?
Serving the same files statically with nginx works.