Created
August 8, 2016 11:56
-
-
Save rumkin/c4c5d61d5408bbcea724960edd18c026 to your computer and use it in GitHub Desktop.
Koa boilerplate code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Router from 'koa-router'; | |
export function moduleMiddleware(options = {}) { | |
const router = new Router(); | |
router.get('/', async (ctx, next) => { | |
// ... do some job | |
}); | |
return router; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Koa from 'koa'; | |
import config from 'config'; | |
import {moduleMiddleware} from './middleware.js'; | |
const app = new Koa(); | |
app.use(moduleMiddleware()); | |
app.listen(config.server.port, config.server.host, function () { | |
console.log('%s listening at port %d', config.app.name, config.server.port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ошибка! На 10-й строке
middleware.js
должно бытьreturn router.routes().
Ссылка на документацию https://www.npmjs.com/package/koa-router#module_koa-router--Router+routes