所以我的路由器看起来像这样:
const app = express();
app.use('/login', router);
app.listen(3000, () => {
app._router.stack.forEach((middleware: any) => {
console.log(middleware);
})
})
当我控制台 .log 该中间件时,我得到:
Layer {
handle:
{ [Function: router]
params: {},
_params: [],
caseSensitive: undefined,
mergeParams: undefined,
strict: undefined,
stack: [ [Layer] ] },
name: 'router',
params: undefined,
path: undefined,
keys: [],
regexp:
{ /^\/login\/?(?=\/|$)/i fast_star: false, fast_slash: false },
route: undefined }
只有我可以看到中间件的路由路径的部分是正则表达式,但它不容易提取......
知道如何从快递应用程序中获取路径