2016-04-21 19 views
2

Ich brauche für die weitere Verarbeitung, dhBenutzerdefinierte URL in Knoten Express

localhost den vollständigen Pfad als String zu speichern: 3000/abc/xyz/etc

würde mir:

„/ abc/xyz/etc“

ich versuchte

app.get('/.+:path', function(req, res) { 
    console.log('path:'+req.params[0]); 
}); 

Aber es funktioniert nicht. Irgendwelche Ideen?

+0

Ist das, was Sie suchen ? http://stackoverflow.com/a/10185427/5812121 – timolawl

Antwort

2
app.get('/:path*', function(req, res) { 
    console.log(req.params.path + req.params[0]); 
}); 
+0

funktioniert wie ein Charme, danke! – user3601578

+0

Hinweis: req.url ist der tatsächliche Pfad – user3601578

0

Es ist unklar, was die Strecke ist und was die params aber dies ist ein guter Ausgangspunkt:

app.get('/abc/:path', function(req, res) { 
    console.log('path:'+req.params.path); 
}); 

Wenn Sie localhost:3000/abc/xyz nennen Sie erhalten path:xyz

Verwandte Themen