Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing a URL as a parameter to Node/Express app

I have a simple Node/Express route, as follows:

var app = express();

app.get('gettags/:page', function(request,response)
{
    var thePage = request.params.page;
    ...
    ...
}

The problem I'm having is that if I pass a URL as the parameter, I get a "Cannot GET" error. So, if I call this like:

http://www.mynodeapp.com/gettags/http://www.someurl.com/?withquery=something

I get the "Cannot GET" error. It's been a couple years since I've used Node, so I am probably forgetting something very basic. But I can't get past this, and Googling this issue hasn't turned up anything useful.

Thanks for any help!

like image 300
Lew Avatar asked Apr 24 '26 01:04

Lew


1 Answers

Your node code looks fine but for this to work you'll 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

like image 86
Andrew Lavers Avatar answered May 05 '26 09:05

Andrew Lavers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!