2016-03-30 32 views
0

ile URL Parametreler başlangıcı alamayan:ExpressJS Ben 'http veya https' Aslında örneğin bir URL benim URL'den param elde edebilmek istiyorum

http://mywebsite.com/new/http://www.url.com 

O sadece iyi çalışır herhangi bir dize ama param olarak bir URL (bir dize http ile başlayan) bu hatası alıyorum geçerken:

app.param('url', function(req, res, next, url) { 

    if (isURL(url)) { 

     req.url = url; 

    } else { 

     res.end('Invalid URL'); 

    } 

    next(); 

}); 

app.get('/new/:url', function(req, res) { 

    var url = req.url; 

    res.end(url); 

}); 

var port = process.env.PORT || 8080; 

app.listen(port, function() { 

    console.log('Listening on port ' + port + '...'); 

}); 

: Burada

Cannot GET /new/http://www.url.com 

benim kodudur Çok teşekkürler.

+1

parametresini kodlayan URL'yi denediniz yapabilir? Örneğin http://mywebsite.com/new/http%3A%2F%2Fwww.url.com – binarymax

+0

Şimdiden şimdi denedim ve teşekkür ederim, şimdi tek yapmam gereken bir yol bulmak. kodlanmış URL'ye doğru olmadan çalışmak, kullanıcı dostu değil –

cevap

2

ExpressJS otomatik url ayrıştırır ve '/' ile segmentlere bölmek, aşağıdaki

app.get('/new/:url*', function(req, res) { 

    var urlInTheParam = req.params['url'] + req.params[0]; 
    //Then you can do you things with the url in the params 

});