如何在索引中定義前綴或每個模塊至少定義一個前綴?
目前我有這個:
角色模塊
export class RoleRoutes extends RouteConfig {
constructor(app: Application) {
super(app, "/role");
}
configureRoutes() {
this.app.route(process.env.PREFIX this.getName() '/:id').get([JWT.authenticateJWT, RoleController.getOne.bind(RoleController)]);
this.app.route(process.env.PREFIX this.getName()).get([JWT.authenticateJWT, RoleController.getAll.bind(RoleController)]);
this.app.route(process.env.PREFIX this.getName()).post([JWT.authenticateJWT, RoleController.create.bind(RoleController)]);
this.app.route(process.env.PREFIX this.getName()).put([JWT.authenticateJWT, RoleController.update.bind(RoleController)]);
return this.app;
}
}
指數
const routes: Array<RouteConfig> = [];
routes.push(new RoleRoutes(app));
我看到了不同的解決方案,但它們與我的結構不匹配。
uj5u.com熱心網友回復:
使用路由器。在頂部添加
const express = require('express')
(或者你匯入的東西)然后在你的定義中
configureRoutes() {
var router = express.Router();
router.use(JWT.authenticateJWT);
router.get('/:id', RoleController.getOne.bind(RoleController))
router.get('/', RoleController.getAll.bind(RoleController));
router.post('/', RoleController.create.bind(RoleController));
router.put('/', RoleController.update.bind(RoleController));
this.app.use(process.env.PREFIX this.getName(), router)
return this.app;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/322893.html
上一篇:fs.readfile更改全域陣列的范圍,并且不能在它之外使用
下一篇:工業領域產品經理的尷尬處境
