unnecessary "ENOENT" console.error when serving a spa
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 43.3k
- Forks
- 2.7k
- PR merge metrics
- No merged PRs in 30d
Description
What's going wrong?
If you serve a SPA with the suggested ecosystem file or the CLI-command from the documentation (https://pm2.keymetrics.io/docs/usage/expose/), URL calls from paths that do not resolve to a file in the build directory (common for a SPA), but that resolves to a route in the front-end router, a console.error according to the pattern: "Error while serving ... with content-type ...: ..." is printed.
However, this is unnecessary because the page still resolves to the corresponding component through the front-end router, so there is no error in the SPA itself.
How could we reproduce this issue?
- create a react app (https://github.com/facebook/create-react-app)
- configure a Browser-Router (https://reactrouter.com/web/api/BrowserRouter) containing a
<Switch> - build the react app (npm)
- serve the application with pm2 as spa
- open a URL that represents an existing Route in the Browser-Router but not an existing file in the build-directory
- watch pm2 error-log
Supporting information
pm2d version: 5.1.0
node version: 14.15.4
arch: x64
platform: linux
os: CentOS Stream 8
A possible fix
/lib/API/Serve.js -> line 275:
if ((!options.spa || file == options.homepage)) {
instead of:
if ((!options.spa || request.wantHomepage)) {
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect lib/API/Serve.js around line 275, then reproduce the behavior with a React SPA using BrowserRouter and a route that is not a build-directory file. Verify that valid SPA routes no longer produce the ENOENT console.error while genuine serving errors still do.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js, react
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100