且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何为所有节点/快速路由添加前缀

更新时间:2023-12-01 10:53:58

您可以为此使用 express Router().

You can use the express Router() for this.

您可以像使用 Express 应用程序一样使用路由器.例如:

You can use the router like you would use your express app. So for example:

router.use(() => {}); // General middleware
router.get('/route1', () => {})
router.get('/route2', () => {})
router.post('/route2', () => {})

然后使用以下命令将路由器连接到您的 Express 应用程序:

And then attach the router to your express app using:

app.use('/prefix', router);

https://expressjs.com/en/4x/api.html#router