1 Star 0 Fork 0

solocode/eggjs-go-examples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

eggjs-go-examples

node API实例基础库,基于Egg.js,用于快速集成开发前后端分离的服务端。 涵盖mysql、redis、mongodb、Mock数据服务&生成文档、服务器渲染(ejs)、curl、定时任务、RESTful接口开发、文件上传、单元测试、token验证、数据加密、日志定制等

QuickStart

$ mkdir myegg & cd myegg
$ npm i
$ npm install apidoc -g
$ npm run local
$ open http://localhost:7001/

Development

$ npm run local             //启动local环境
$ npm run uat               //启动uat测试环境
$ npm run prod              //启动生产环境
$ npm run stage             //启动stage环境
$ npm stop                  //停止服务
$ npm run document          //生产API文档
$ npm run test              //单元测试 mocha

链接数据库 (mysql, mongoDB, redis)

参见 ./app/router.js
其中包含操作实例,包含mysql, mongoDB增删改查及分页请求;redis设置读取
启动步骤:
1、./config/plugin.js 将对应插件的enable设置为true
2、./config/config.defaule.js 配置连接信息 

mongoDB API参见 mongoosejs

mysql API参见 egg-mysql API较少不能满足可使用 app.mysql.query(sql, values);

生产mock数据及生产API文档

参见 ./app/router.js 
参见 ./app/controller/testMock.js 其中包含Mockjs、apidocs实例
npm run document //生成文档 生成apidoc文件夹

mockjs 规则参见 mockjs

apidoc 规则参见 apidoc

token生成及验证

参见 ./app/router.js 
参见 ./app/controller/testJWT.js 
实例包含:登录获取token,通过中间件token_handler.js 验证
PS:中间件启用模式为通过自定义URL识别 见config文件
    中间件相关文档可见eggjs官方文档

curl

参见 ./app/router.js 
参见 ./app/controller/testCURL.js 
参见 ./app/service/mycurl.js 
实例包含:明文请求&DES3加密请求,DES3密钥可在config中设置 

日志

参见 ./app/service/mycurl.js 
eggjs启动后自动生成日志,日志位置./logs
PS: 自定义日志,开启方式见./config/config.defaule.js ,在curl实例中包含自定义日志的生成方式

数据加密

参见 ./app/extend/helper.js 
实例包含:md5 + DES3加密解密

静态文件管理

参见./config/config.defaule.js中config.static

图片上传

参见 ./app/controller/testUpload.js 
实例包含:单个文件及多个文件上传 适用UI为antd & antd-m

定时任务

参见 ./app/schedule/..
实例包含:启动单一worker定时任务及所有worker定时任务,定时任务启动时机可根据业务或在./app.js中根据生命周期启动

单元测试

参见 ./app/test/..
实例包含:eslint检测及token验证的单元测试 ,单元测试使用mocha
npm run test //运行单元测试 首先会检测eslint

restful

参见 ./app/router.js 

服务器渲染(ejs)

参见 ./app/controller/home.js
实例包含:通过ejs模板渲染页面

websocket

下版本待续
MIT License Copyright (c) 2019 高超 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

操作mysql、redis、mongodb、Mock数据服务&生成文档、服务器渲染(ejs)、curl、定时任务、RESTful接口开发、文件上传、单元测试、token生成及验证、数据加密(MD5,DES)、日志定制等 展开 收起
README
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/solocoding/eggjs-go-examples.git
git@gitee.com:solocoding/eggjs-go-examples.git
solocoding
eggjs-go-examples
eggjs-go-examples
master

搜索帮助