與所有/管理頁面匹配的快速路線

[英]Express route that matches all /admin pages


I am trying to define a route in express that matches any /admin requests like /admin/users, /admin/settings or /admin/profile/user , not including /admin or /admin/ ,as they are meant for login, to check if the connection is https and if the admin is logged in.

我試圖在快遞中定義一個路由,匹配任何/管理員請求,如/ admin / users,/ admin / settings或/ admin / profile / user,不包括/ admin或/ admin /,因為它們用於登錄,到檢查連接是否為https,以及管理員是否已登錄。

I've tried various regex such as:

我嘗試了各種正則表達式,例如:

/admin/:var()
/admin/.*
/admin/*
/admin/var(*)

But none seem to work.For the routing I am using:

但似乎沒有工作。對於我正在使用的路由:

app.use('/admin/:var(.{1,})',function(req,res,next){
    res.send("hello world");
    console.log("matched "+req.params.var);
});

1 个解决方案

#1


0  

A route like this:

像這樣的路線:

app.use('/admin/:more', function(req, res, next) {
    console.log(`req.path: ${req.path}`);
    // check admin login and https here
    next();
});

does not match /admin or /admin/, but does match /admin/anythingelse and /admin/anythingelse/andmore which is what I think you asked for.

與/ admin或/ admin /不匹配,但匹配/ admin / anythingelse和/ admin / anythingelse / andmore這是我認為你要求的。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2017/06/29/725ca2d4111cfe62f020adbf4aaeb93f.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com