koahubjs / Koahub
Licence: mit
KoaHub.js -- 中文最佳实践Node.js Web快速开发框架。支持Koa.js, Express.js中间件。当前项目已停止维护,推荐使用Doodoo.js
Stars: ✭ 308
Projects that are alternatives of or similar to Koahub
Cool Admin Api
cool-admin-api 是基于egg.js、typeorm、jwt等封装的api开发脚手架、快速开发api接口
Stars: ✭ 188 (-38.96%)
Mutual labels: koa, koa2, koajs
koahub-cli
KoaHub CLI -- KoaHub.js的开发工具,自动babel编译 ES6/7(Generator Function, Class, Async & Await)并且文件修改后自动重启。
Stars: ✭ 16 (-94.81%)
Mutual labels: koa, koajs, koa2
Vue Chat
👥Vue全家桶+Socket.io+Express/Koa2打造一个智能聊天室。
Stars: ✭ 887 (+187.99%)
Mutual labels: koa, koa2, koajs
Koach Javascript
Production ready Koa2 boilerplate.
Stars: ✭ 79 (-74.35%)
Mutual labels: koa, koa2, koajs
koa-smart
A framework base on Koajs2 with Decorator, Params checker and a base of modules (cors, bodyparser, compress, I18n, etc…) to let you develop smart api easily
Stars: ✭ 31 (-89.94%)
Mutual labels: koajs, koa2
stack
A set of components for makers to ship better products faster 🚀
Stars: ✭ 27 (-91.23%)
Mutual labels: koajs, koa2
koa-orm
koa orm using sequelize & sk2 (fork from knex)
Stars: ✭ 62 (-79.87%)
Mutual labels: koajs, koa2
node-typescript-starter
REST API using Node with typescript, KOA framework. TypeORM for SQL. Middlewares JWT (auth), CORS, Winston Logger, Error, Response
Stars: ✭ 19 (-93.83%)
Mutual labels: koa, koa2
koa-simple-ratelimit
Simple rate limiter for Koa.js v2 web framework
Stars: ✭ 17 (-94.48%)
Mutual labels: koa, koa2
express-to-koa
Use express middlewares in Koa2, the one that really works.
Stars: ✭ 18 (-94.16%)
Mutual labels: koa, koa2
koa
A golang framework like koa.js and has the best performance with net/http.
Stars: ✭ 30 (-90.26%)
Mutual labels: koa, koajs
inversify-koa-utils
inversify-koa-utils is a module based on inversify-express-utils. This module has utilities for koa 2 applications development using decorators and IoC Dependency Injection (with inversify)
Stars: ✭ 27 (-91.23%)
Mutual labels: koa, koa2
KoaHub.js
KoaHub.js -- 中文最佳实践Node.js Web快速开发框架。支持Koa.js, Express.js中间件。当前项目已停止维护,推荐使用Doodoo.js
//base controller, admin/controller/base.controller.js
module.exports = class extends koahub.controller {
async _initialize() {
console.log('base _initialize');
}
async isLogin() {
console.log('base isLogin');
}
}
//index controller, admin/controller/index.controller.js
const 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
特性
- 支持koa全部中间件
- 支持使用 ES6+ 全部特性来开发项目
- 支持断点调试 ES6+ 项目
- 支持多种项目结构和多种项目环境
- 支持 Controller 中使用Koa.js的所有API
- 支持多级 Controller
- 支持自动加载
- 支持钩子机制
- 支持 Socket.io
- 支持错误处理
- 支持全局koahub变量
- 支持快捷方法
- 支持修改代码,立即生效
- 支持前置,后置,空操作
- 支持禁用控制器方法
- 支持 Restful 设计
- 支持 Common 自动加载
- 支持启动自定义
- ...
安装
npm install koahubjs/koahub --save
创建启动文件
// app/index.js启动文件
const Koahub = require('koahub');
// 初始化项目
const app = new Koahub();
// 启动项目
app.run();
方法
ctx上的函数或参数将自动加载到controller,例如支持 this.body = 'Hello World!'
, ctx中具体的API请参考Koa.js, 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.js
module.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.js
module.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
// 下载demo
git clone https://github.com/koahubjs/koahub-demo.git
// 进入项目
cd koahub-demo
// 安装依赖
npm install
// 启动项目
npm start
promise
// 下载demo
git clone https://github.com/koahubjs/koahub-demo-promise.git
// 进入项目
cd koahub-demo-promise
// 安装依赖
npm install
// 启动项目
npm start
generator
// 下载demo
git 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
使用手册
官网
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].