Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

catchall route hard to debug #19

Open
nathanallen opened this issue Feb 24, 2017 · 1 comment · May be fixed by #20
Open

catchall route hard to debug #19

nathanallen opened this issue Feb 24, 2017 · 1 comment · May be fixed by #20

Comments

@nathanallen
Copy link
Contributor

nathanallen commented Feb 24, 2017

Lots of confusing bugs emerge due to the catchall/wildcard/splat route serving HTML. The most common example is /wrong/path/to/some.js raising "SyntaxError: unexpected token <" in the client.

Recommendation:

  • limit catchall to only known route patterns (e.g. /albums, /albums/:id, /albums/:id/songs, etc).
  • but add a final catchall that responds with a status 404.
@mnfmnfm
Copy link

mnfmnfm commented Feb 24, 2017

Specifically, nathan's suggested code is:

app.get([
  '/albums',
  '/albums/:albumId',
  '/albums/:albumId/songs',
  '/albums/:albumId/songs/:songId'
], function homepage (req, res) {
  res.sendFile(__dirname + '/views/index.html');
});

app.get("*", function notFound(req, res){
  res.sendStatus(404);
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants