2015-09-15 54 views
1

試圖單獨的API和Web路線:單獨的API和Web的路線

路線/ 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); 

但沒有成功路。

+0

這是一個錯字? var wen = function(){...也許它應該是web – Oscar

+0

我改變它,不,它不是那個問題,api也不能訪問。 – Alvin

回答

0

我必須將其更改爲它工作:

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