Giter Site home page Giter Site logo

sanlex / eggjs-go-examples Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gcdreams/eggjs-go-examples

0.0 1.0 0.0 84 KB

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

License: MIT License

JavaScript 98.92% HTML 1.08%

eggjs-go-examples's Introduction

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

下版本待续

eggjs-go-examples's People

Contributors

gcdreams avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.