- /app 主目录
 - /config 配置目录
 - /test 测试目录
 - /logs 日志文件
 - /run 项目运行生成的
 - autod.conf.js
 
MVC架构图

egg mvc时序图

服务端架构
服务器端通常采用三层体系架构,分别
- 表现层 web
 - 业务逻辑层 service
 - 持久层 DAO
 
- mvc第一步,编写 controller & router
 - http的所有请求都放在 services目录下
- models下 调用 serivces
├── app│ ├── controller│ │ └── news.js│ ├── middleware│ │ └── robot.js│ ├── public│ ├── router.js // 定义路由│ ├── routes│ ├── schedule│ │ └── update_cache.js│ ├── service│ │ └── news.js│ └── view│ └── news.html //模板 news.ejs, news.njk├── app.js├── config│ ├── config.default.js // config目录配置 key│ └── plugin.js├── database│ └── config.json├── docs│ ├── egg.md│ └── images│ ├── controller1.jpg│ └── npx\ sequelize.jpg├── logs│ └── eggjs│ ├── common-error.log│ ├── egg-agent.log│ ├── egg-schedule.log│ ├── egg-web.log│ └── eggjs-web.log├── package-lock.json├── package.json└── run├── agent_config.json├── agent_config_meta.json├── agent_timing_2416.json├── application_config.json├── application_config_meta.json└── router.json
 
 - models下 调用 serivces
 
app
controller
view
service
读取 数据库,远程接口
- 添加配置
 - 编写 service 代码
 编写 controller 代码
创建数据模型
- 模板和路由
 - 开发接口
 
controller调用 services
services里面调用数据库
findOne
const res = await User.findOne({attributes: ['id', 'username', 'nickname', 'city', 'address'],where: { username: 'lucy', password: '123' }});if(!res) return null;//cors跨域配置config.security = {csrf: {enable: false,},domainWhiteList: ['*'], //允许访问域名的白名单,*表示都能访问}config.cors = {origin: '*',allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS', //允许请求的方法}
egg渐进式开发
https://www.axihe.com/edu/egg/tutorials/progressive.html
https://blog.csdn.net/aSuncat/article/details/114092145
https://blog.csdn.net/aSuncat/article/details/114092145
