Skip to content
Discussion options

You must be logged in to vote

trailing slash is considered a different URL so it's not a bug, you could check for trailing slash in your handler and remove it or redirect to non-trailing slash url:

// remove trailing slash before processing request
app.any('/*', (res, req) => {
  const method = req.getMethod()
  let path = req.getUrl()
  if(path.endsWith('/') && path != '/') path = path.slice(0,-1)
  switch(method) {
    case 'get': switch(path) {
      case '/': return res.end(`get ${path}`)
      case '/foo': return res.end(`get ${path}`)
      case '/bar': return res.end(`get ${path}`)
    } break
    case 'post': switch(path) {
      case '/': return res.end(`post ${path}`)
      case '/foo': return res.end(`post ${

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #336 on December 09, 2020 04:00.