Guilherme Salomé Guilherme Salomé - 5 months ago 8
Node.js Question

GET a website url when routing

Sorry, my vocabulary is very limited, any help clarifying this question is deeply appreciated.

I'm building a server using Nodejs and Express, it has a route like

/new/:url
. I access the value passed on the url by using
req.params.url
. This works well for simple strings, like
chocolate
, however, if I pass a website url, like
http://www.google.com
, then it won't be routed to
/new/:url
.

Question: how can I pass a website url and access it with Node/Express?

Edit: I am trying to use the GET method, and apparently a way to solve this problem is through Wildcards/Regex.

Thank you very much for helping!

Answer

The solution that worked for me was Regex. Instead of routing as /new/:url, I used:

/new/:url(*)

So that if http://www.google.com is given as a parameter:

req.params.url = "http://www.google.com"
Comments