K
K
Klein Maximus2017-10-17 22:23:16
Node.js
Klein Maximus, 2017-10-17 22:23:16

How to set a route with a colon (:) in Express.js?

It is required to configure express to respond to a request like GET /s/x:y:z
But there is a problem, because the colon is used in the named parts of the route.
A construction like /s/x\:y\:z doesn't work for some reason :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Klein Maximus, 2017-10-17
@kleinmaximus

I found a solution - as a template, you need to use not a string, but a regular expression.
That is, not and not , butapp.use('/s/x:y:z')app.use('/s/x\:y\:z')app.use(/^\/s\/x\:y\:z$/)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question