Skip to content

Latest commit

 

History

History
63 lines (44 loc) · 816 Bytes

README.md

File metadata and controls

63 lines (44 loc) · 816 Bytes

node-box

基于 koa 封装轻量级的 node 应用,开箱即用

安装

npm i @pkb/node-box -g # 全局安装/本地安装

node-box build # 构建项目
node-box watch # 开发模式

目录

-- app 
  -- controller
  -- router
-- public # 静态资源

controller 示例

controller/home.js

'use strict';

class HomeController {
  async one({ ctx, next }) {

    ctx.body = {
      content: 'one',
    };
  }

  async two({ ctx, next }) {

    ctx.body = {
      content: 'two',
    };
  }
}

module.exports = HomeController;

router 示例

router/home.js

'use strict';

module.exports = app => {
  const { router, controller } = app;

  router.get('/one', controller.home.one);
  router.get('/two', controller.home.two);
  router.get('/');
};