https://github.com/delicatejs/delicatejs
👜一款基于koa、开箱即用的轻量级后端框架
https://github.com/delicatejs/delicatejs
backend koa2 mvc node nodejs web webserver
Last synced: about 2 months ago
JSON representation
👜一款基于koa、开箱即用的轻量级后端框架
- Host: GitHub
- URL: https://github.com/delicatejs/delicatejs
- Owner: delicatejs
- License: mit
- Created: 2018-04-30T14:16:29.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-10-30T03:11:57.000Z (over 7 years ago)
- Last Synced: 2025-09-20T23:24:56.658Z (9 months ago)
- Topics: backend, koa2, mvc, node, nodejs, web, webserver
- Language: TypeScript
- Homepage: http://www.sunyangjie.com/2018/04/29/nodejs%E7%89%88web%E4%B8%9A%E5%8A%A1%E5%B1%82%E6%A1%86%E6%9E%B6/
- Size: 128 KB
- Stars: 0
- Watchers: 0
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [DelicateJS](http://www.sunyangjie.com/2018/04/29/nodejs%E7%89%88web%E4%B8%9A%E5%8A%A1%E5%B1%82%E6%A1%86%E6%9E%B6/)· [](https://github.com/delicatejs/delicatejs/blob/master/LICENSE) [](https://www.npmjs.com/package/delicate)
一套基于`koa`的轻量级`mvc`框架,旨在让基于 node 的 Web`接口`开发变得更便捷,更灵活,更高效
💀 **注意**
- 不推荐使用该框架进行服务端模板渲染,如果实在要实现服务端渲染,推荐基于 react 的同构框架[next.js](https://github.com/zeit/next.js)
- 该框架注重于基于 api 的后端业务,取消了内置的模板引擎,专注于后端业务层,即`Model和Controller`,弱化了`View`
- 目前框架处于调整期,已经加入 socket 功能
- 整体设计思路参考[CodeIgniter](https://github.com/bcit-ci/CodeIgniter)
### Setup
```
$ cd example
$ node index.js
```
访问 `http://localhost:3001/` [more>](https://github.com/delicatejs)
### Deployment
使用 [pm2](https://github.com/Unitech/pm2) 进行项目的部署服务
### 更新日志
- 服务端返回形式
- 正常返回
```js
//例如返回json格式的数据
this.ctx.set('Content-Type', 'text/json');
this.ctx.body = {};
```
- 模板返回
```js
//指定模板的路径和模板需要渲染的数据[数组]
this.view(templatePath, templateData);
```
- 重定向
```js
//重定向到路由为'/'的页面
this.redirect('/');
```
* 请求方式检测
```js
//core MY_Controller
module.exports = class extends DJ_Controller {
constructor(ctx) {
super(ctx);
this.MethodNotAllowed(() => {
this.ctx.status = 405;
this.ctx.body = 'Method Not Allowed';
});
}
};
//controllers
//目前支持请求方式 'get', 'post', 'delete', 'head', 'options', 'put', 'patch'
module.exports = class extends MY_Controller {
async delete() {
/*
* 指定当前接受的请求方式
* 如果请求方式不是delete,会执行this.MethodNotAllowed的回调方法
* 如果不指定method,也可以直接写业务,但是这个会任何请求方式都会命中该路由
*/
//指定单个请求方式
await this.method.delete();
//指定多个请求方式
await this.method('delete', 'post');
//指定不同的请求方式的业务代码
//必须要先指定所有可能的请求方式
//await this.method('post', 'delete')
this.method.post(async () => {
//post请求方式的业务代码
});
this.method.delete(async () => {
//delete请求方式的业务代码
});
//编写业务代码
//更多查看最佳实践delicatejs-example
}
};
```
### More
更多使用姿势,请参考[example](https://github.com/delicatejs/delicatejs-example)
### License
MIT