跳到主要内容

1 篇博文 含有标签「express」

查看所有标签

· 阅读需 2 分钟

比如我们注册了如下的路由

app.get('/', function (...) { ... });
app.get('/foo/:id', function (...) { ... });
app.post('/foo/:id', function (...) { ... });

然后想要获得的东东是这样的形式:

{
get: [ '/', '/foo/:id' ],
post: [ '/foo/:id' ]
}

该肿么办呢?

在 express 3.x 中

只需要 app.routes 就可以啦

在 express 4.x 中

Applications - built with express()

app._router.stack

Routers - built with express.Router()

router.stack

更多的答案尽在 StackOverflow how-to-get-all-registered-routes-in-express