在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:koahub开源软件地址:https://gitee.com/koahubjs/koahub开源软件介绍:wemall商城&koahub商城所有系统将于4月底或5月初开放免费下载,具体请联系客服咨询 KoaHub.jsKoaHub.js -- 中文最佳实践Node.js Web快速开发框架。支持Koa.js, Express.js中间件。当前项目已停止维护,推荐使用Doodoo.js //base controller, admin/controller/base.controller.jsmodule.exports = class extends koahub.controller { async _initialize() { console.log('base _initialize'); } async isLogin() { console.log('base isLogin'); }}//index controller, admin/controller/index.controller.jsconst base = require('./base.controller');module.exports = class extends base { async _initialize() { await super._initialize(); } async index() { this.view(1); } async index2() { this.json(1, 2); } async index3() { await this.render('index'); }} 环境要求:Node.js >= 7.6.0 特性
安装npm install koahubjs/koahub --save 创建启动文件// app/index.js启动文件const Koahub = require('koahub');// 初始化项目const app = new Koahub();// 启动项目app.run(); 方法ctx上的函数或参数将自动加载到controller,例如支持 this.ctx;this.next;this.isGet();this.isPost();this.isAjax();this.isPjax();this.isMethod(method);this.hook.add(name, action);await this.hook.run(name, ...args);this.download(file);this.view(data);this.json(data, msg, code);this.success(data, msg);this.error(data, msg);await this.action(path, ...args); 快捷方法// app/common.js 函数文件module.exports = { add(a, b){ return a + b; }}// 控制器中可以直接通过this.add调用 快捷中间件app.use(async function (ctx, next) { ctx.model = function() { // .... } await next();});// 控制器中可以直接通过this.model调用 命令行工具配置// app/config/default.config.jsmodule.exports = { port: 3000, default_module: 'admin'}//框架默认配置//启动端口port: 3000,//默认模块,控制器,操作default_module: 'home',default_controller: 'index',default_action: 'index',//url后缀url_suffix: '',//自动加载配置loader: { "controllers": { root: 'controller', suffix: '.controller.js', prefix: '/', }, "configs": { root: 'config', suffix: '.config.js' }, "middlewares": { root: 'middleware', suffix: '.middleware.js' }}//中间件默认配置//middleware顺序middleware: ['koa-logger'],//http日志'koa-logger': true,//favicon设置'koa-favicon': 'www/favicon.ico',//body配置body: { multipart: true},//cors配置'koa-cors': false,//session配置'koa-session2': false,//static配置'koa-static-cache': false 其他// 控制器初始化,前置,后置,空操作async _initialize()async _before()async _before_index()async index()async _after_index()async _after()async _empty()// 控制器私有方法// 方法首页字符是`_`为私有方法// 支持restful路由设置// app/config/router.config.jsmodule.exports = [ ['/product', { get: "/home/product/index" }], ['/product/:id', { get: "/home/product/detail", post: "/home/product/add", put: "/home/product/update", delete: "/home/product/delete", }]] 开始应用async/await// 下载demogit clone https://github.com/koahubjs/koahub-demo.git// 进入项目cd koahub-demo// 安装依赖npm install// 启动项目npm start promise// 下载demogit clone https://github.com/koahubjs/koahub-demo-promise.git// 进入项目cd koahub-demo-promise// 安装依赖npm install// 启动项目npm start generator// 下载demogit clone https://github.com/koahubjs/koahub-demo-generator.git// 进入项目cd koahub-demo-generator// 安装依赖npm install// 启动项目npm start 启动信息[2017-05-14 11:48:05] [Koahub] Koahub Version: 2.2.6[2017-05-14 11:48:05] [Koahub] Koahub Website: http://js.koahub.com[2017-05-14 11:48:05] [Koahub] Nodejs Version: v8.0.0[2017-05-14 11:48:05] [Koahub] Nodejs Platform: darwin x64[2017-05-14 11:48:05] [Koahub] Server Enviroment: development[2017-05-14 11:48:05] [Koahub] Server running at: http://127.0.0.1:3000 使用手册官网 |
2022-08-15
2022-08-17
2022-09-23
2023-10-27
2022-08-18
请发表评论