Unitech / Unitech/pm2

unnecessary "ENOENT" console.error when serving a spa

Open
#5,117 1 comment 3 reactions 0 assignees View on GitHub

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?

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.