Node.js 在路由中分离api和web
正在尝试分离api和web路由: route/index.jsNode.js 在路由中分离api和web,node.js,express,Node.js,Express,正在尝试分离api和web路由: route/index.js var api = function () { router.get('/:id', function (req, res, next) { ... }); return router; } var web = function () { router.get('/:id', function (req, res, next) { ... }); re
var api = function () {
router.get('/:id', function (req, res, next) {
...
});
return router;
}
var web = function () {
router.get('/:id', function (req, res, next) {
...
});
return router;
}
module.exports = {
api: api,
web: web
};
app.js
var indexAPI = require('./app/routes/accounts').api;
var indexWeb = require('./app/routes/accounts').web;
app.use('/api/index', indexAPI);
但它没有成功路由。我已将其更改为,并且它正在工作:
var api = (function () {
router.get('/:id', function (req, res, next) {
...
});
return router;
})();
var web = (function () {
router.get('/:id', function (req, res, next) {
...
});
return router;
})();
module.exports = {
api: api,
web: web
};
我已将其更改为,并且它正在工作:
var api = (function () {
router.get('/:id', function (req, res, next) {
...
});
return router;
})();
var web = (function () {
router.get('/:id', function (req, res, next) {
...
});
return router;
})();
module.exports = {
api: api,
web: web
};
是打字错误吗?var wen=function(){…可能应该是webI更改它,不,不是那个问题,api也不可访问。这是一个打字错误?var wen=function(){…可能应该是webI更改它,不,不是那个问题,api也不可访问。