Egg.js体验
- 全局安装
// 创建项目
$ npm i egg-init -g
$ egg-init egg-example --type=simple
$ cd egg-example
$ npm i
// 启动项目
$ npm run dev
$ open localhost:7000
Egg.js的结构
- 路由(Router): 将请求URL和具体承担执行动作的Controller的关系对应
- 控制器(Controller):
- Restful: 接收用户的参数,从数据中查找内容返回给用户
- 页面请求: 根据用户访问不同的URL,渲染不同的模板得到HTML返回给用户
- 代理服务器: 将用户的请求转发到其他服务器上.
- 服务(Service):
- Service就是将复杂业务场景下用于做业务封装的一个抽象层
- 好处:
- 保持Controller简洁
- 业务逻辑独立性: 用户业务PCController + MobileController
- 逻