简体   繁体   English

快速路由匹配网址

[英]express routing match a url

what regex should one use in express to match a url. 正则表达式中应该使用什么正则表达式来匹配网址。 If my endpoint looks like this 如果我的端点看起来像这样

www.mydomain.com/v1/ https://www.url-to-be-matched.com . www.mydomain.com/v1/ https://www.url-to-be-matched.com

I want to accept https://www.url-to-be-matched.com . 我想接受https://www.url-to-be-matched.com as params. 作为参数。 I have tried this 我已经试过了

var express = require('express');
var app = express();
app.get('/v1/:url',function(req,res){
console.log(req.params.url);
});

The above is not matching the url. 上面的网址不匹配。

我认为您必须使用encodeURI()方法对传递的URL进行编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM