LoginSignup
0
1

More than 5 years have passed since last update.

koa-routerの分割

Posted at

expressでできたんだからkoaでもできる!と意気込んでやってみたことのまとめ

const Koa = require('koa');
const Router = require('koa-router');
const index = require('./routes/index.js');
const user = require('./routes/user.js');

const app = new Koa();
const router = new Router();

router.use('/', index.routes());    // <-ここで目当てのパスに当てはめる
router.use('/user', user.routes()); // 上に同じ 分割できている!

app.use(router.routes());  // 忘れずにアプリケーションにも設定する

以上

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1