An Extensible Node.js Web Architecture
npm i pugna -S
Pugna extends Koa2 and you can use it same as Koa:
const Pugna = require('pugna');
const app = new Pugna();
app.use(ctx => {
ctx.body = 'Hello Pugna!';
});
Pugna provides a function for dynamic loading modules:
app.loadModules(app, __dirname);
Using loadModules
should have the following appointment:
- Use
koa-router
- Each module's name would be used in the application's route rules
- Each module should have
routes
folder and exports the router:
const router = require('koa-router')();
router.get('/', (ctx, next) => {
ctx.body = 'bar index';
});
module.exports = router;
See example.
The MIT License