尝试将api和网络路由分开:

路线/ index.js

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
};

09-10 10:22
查看更多