KoaHub.js Node.js Web 快速开发框架开源项目

我要开发同款
匿名用户2016年09月07日
185阅读

技术信息

开源地址
https://gitee.com/koahubjs/koahub
授权协议
MIT

作品详情

KoaHub.js--中文最佳实践Node.jsWeb快速开发框架。支持Koa.js,Express.js中间件,可以直接在项目里使用ES6/7(GeeratorFuctio,Class,Asyc&Await)等特性,借助Babel编译,可稳定运行在Node.js环境上。

//base cotroller, app/cotroller/home/base.cotroller.jsexport default class exteds koahub.http {    asyc _iitialize() {        cosole.log('base _iitialize');    }    asyc isLogi() {        cosole.log('base isLogi');    }}//idex cotroller, app/cotroller/home/idex.cotroller.jsimport base from "./base.cotroller";export default class exteds base {    asyc _iitialize() {        await super._iitialize();    }    asyc idex() {        this.view(1);    }    asyc idex2() {        this.jso(1, 2);    }    asyc idex3() {        await this.reder('idex');    }}

项目中可以使用ES6/7里的所有特性,借助Babel编译,可以稳定运行在>=0.12.0的Node.js环境中。

特性

支持koa全部中间件

支持使用ES2015+全部特性来开发项目

支持断点调试ES2015+项目

支持多种项目结构和多种项目环境

支持多级Cotroller

支持自动加载

支持钩子机制

支持Socket.io

支持错误处理

支持全局koahub变量

支持快捷方法

支持修改代码,立即生效

...

安装pm istall github:koahubjs/koahub --save创建启动文件// app/idex.js启动文件import Koahub from "koahub";//默认app是项目目录cost app = ew Koahub();app.getKoa();获取koa实例化,支持自定义koa中间件app.getServer();获取server实例化,支持socket.ioapp.ru();方法this.ctx;this.ext;this.method();this.isGet();this.isPost();this.isAjax();this.isPjax();this.isMethod(method);this.ip();this.header(ame, value);this.status(code);this.get(ame, value);this.post(ame, value);//需中间件,且快捷方法this.file(ame, value);//需中间件,且快捷方法this.sessio(ame, value);//需sessio中间件this.cookie.get(ame, optios);this.cookie.set(ame, value, optios);this.hook.add(ame, actio);await this.hook.ru(ame, ...args);this.host();this.redirect(url);this.dowload(file);this.view(data);this.jso(data, msg, code);this.success(data, msg);this.error(data, msg);this.state(ame, value);await this.reder(tpl, locals);//需中间件await this.actio(path, ...args);快捷中间件// use koa-better-body 自定义post/file中间件koa.use(asyc fuctio (ctx, ext) {    if (ctx.request.fields) {        ctx.post = ctx.request.fields;    }    if (ctx.request.files) {        ctx.file = ctx.request.files;    }    await ext();});目录结构|-- app   |   |-- addo   |   |   |-- demo   |   |   |   |-- cofig.jso   |   |   |   |-- cotroller   |   |   |   |-- model   |   |   |   `-- view   |   |-- cofig   |   |   |-- idex.cofig.js   |   |-- cotroller   |   |   |-- home   |   |   |   |-- idex.cotroller.js   |   |   |   `-- base.cotroller.js   |   |   |-- admi   |   |-- data   |   |-- model   |   |-- util   |   |-- idex.js   |-- logs   |-- ode_modules   |-- rutime   |-- www   |-- app.js   |-- package.jso命令行工具koahubUsage: koahub [optios] [commad]Commads:start [optios] [script]  koahub start script --watch --compilecotroller [ame]         koahub create cotrollercreate [project]          koahub create projectOptios:-h, --help     output usage iformatio-V, --versio  output the versio umberExamples:koahub start app/idex.js --watch --compile (文件修改自动编译并且重启)koahub cotroller home/article (自动创建控制器模版)koahub create koahub-demo (自动初始化项目)配置// app/cofig/idex.cofig.jsexport default {    port: 3000,    default_module: 'admi'}//启动端口port: 3000,//调试模式debug: true,//默认模块,控制器,操作default_module: 'home',default_cotroller: 'idex',default_actio: 'idex',//favico设置favico: 'www/favico.ico',//hook中间件hook: true,//http日志logger: true,//url后缀url_suffix: '',//自动加载配置 such as koahub.utilsloader: {    "utils": {        root: 'util',        suffix: '.util.js'    }}开始应用git cloe https://github.com/koahubjs/koahub-demo.gitcd koahub-demopm istallpm start启动信息:[2016-11-28 09:56:03] [Koahub] Koahub versio: 1.1.0[2016-11-28 09:56:03] [Koahub] Koahub website: https://js.koahub.com[2016-11-28 09:56:03] [Koahub] Server Eviromet: developmet[2016-11-28 09:56:03] [Koahub] Server ruig at: https://127.0.0.1:3000使用手册

KoaHub.js手册

官网

KoaHub.js官网

功能介绍

KoaHub.js -- 中文最佳实践Node.js Web快速开发框架。支持Koa.js, Express.js中间件,可以直接在项目里使用 ES6/7(Generator Function,...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论