How can I split my koa routes into separate files?

前端 未结 7 1169
一向
一向 2021-01-30 04:20

I\'m trying to figure out how to split my routes into separate files.

I have this so far, but it doesn\'t work. I just get Not found when I try to access

7条回答
  •  鱼传尺愫
    2021-01-30 04:50

    server.js

    var app = require('koa')();
    var router = require('./routes');
    app.use(router.routes());
    app.use(router.allowedMethods());
    app.listen(3000);
    

    routes.js

    var router = require('koa-router')();
    router.get('/', function* () {
        this.body = 'router test';
    });
    module.exports = router;
    

提交回复
热议问题