Skip to content

having issues getting app.get('/@:username') working #3050

Answered by NicoPlyley
redimongo asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @redimongo,

Another way to achieve this would be using Regex. If you write the route as follows:

app.get('/:user{@[a-zA-Z0-9]+}', (c) => {
  const user = c.req.param('user')
  return c.text(user)
})

If you went to /test123, the route would give a 404 error, but if you go to @test123, it will return the user

Also, if you want to allow everything to work, you can do /:user{@.+} instead

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@redimongo
Comment options

@NicoPlyley
Comment options

Answer selected by redimongo
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