Passing url as parameter to Node / Express app
I have a simple Node / Express route as shown below:
var app = express();
app.get('gettags/:page', function(request,response)
{
var thePage = request.params.page;
...
...
}
The problem I am facing is that if I pass in the URL as a parameter, I get a "Can not GET" message. So if I call it like this:
http://www.mynodeapp.com/gettags/http://www.someurl.com/?withquery=something
I get the message "Can not GET". It's been a couple of years since I've been using Node, so I'm probably forgetting something very basic. But I can't get past this, and Googling this issue hasn't brought anything useful.
Thanks for any help!
+3
source to share
1 answer
Your node code looks great, but for that you will need to URI encode your argument:
var url = 'http://www.mynodeapp.com/gettags/' + encodeURIComponent('http://www.someurl.com/?withquery=something')
//becomes: http://www.mynodeapp.com/gettags/http%3A%2F%2Fwww.someurl.com%2F%3Fwithquery%3Dsomething
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
+3
source to share