我正在尝试弄清楚如何将我的路线分成单独的文件。
到目前为止,我已经知道了,但是没有用。Not found
当我尝试访问时我才知道http://localhost:3001/api/things
//server.js
var koa = require('koa');
var app = koa();
var router = require('koa-router');
app.use(router(app));
require('./routes')(app);
// routes.js
module.exports = function *(app){
app.use('/api/things', require('./api/things'));
};
// api/things/index.js
var Router = require('koa-router');
var router = new Router({
prefix: '/api/things'
});
router.get('/', function *(){
this.body = [{ name: 'Foo'}, { name: 'Bar' }];
});
module.exports = router;