简体   繁体   English

Express Router如何路由所有带有查询参数的请求?

[英]Express router how to route all requests with query parameters?

I am using Router module to route all requests to a specific authorization endpoint. 我正在使用路由器模块将所有请求路由到特定的授权端点。

var router = Router();
app.use(router);
router.route('/*')
        .all([auth, function(req, res){
               res.send("Authorized").end();
        }])

This works if my request url looks like /myapp/cat. 如果我的请求网址看起来像/ myapp / cat,则此方法有效。 But does not work if it is /myapp/cat?eyecolor=brown. 但是,如果它是/ myapp / cat?eyecolor = brown,则不起作用。

Is there any specific regex format I need to use to get the router recognize ? 我需要使用任何特定的正则表达式格式来识别路由器吗? character and such? 性格之类的?

This might help you. 这可能对您有帮助。

"There is a special routing method, app.all(), which is not derived from any HTTP method. It is used for loading middleware at a path for all request methods." “有一个特殊的路由方法app.all(),它不是从任何HTTP方法派生的。它用于为所有请求方法的路径加载中间件。” So I'm not exactly sure about router.route(). 所以我不太确定router.route()。 http://expressjs.com/guide/routing.html http://expressjs.com/guide/routing.html

Second: look at examples of route paths based on regular expressions at the above page. 第二:在上一页中查看基于正则表达式的路由路径示例。 /.*fly$/ accepts butterfly, dragonfly, but not flybird. /.*fly$/接受蝴蝶,蜻蜓,但不接受飞鸟。 I think your mistake might be the ' ' of you little regexp. 我认为您的错误可能是您小的正则表达式的问题。

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

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