'use strict';
const Controller = require('egg').Controller;
class ProductController extends Controller {};
module.exports = ProductController;
Router用来主要用来描述URL和具体承担执行动作的Controller的对应关系,用于统一路由规则。所以关于路由的配置都会放在app/router.js下面。
controller下面主要是放各个业务逻辑,比如,首页模块、用户模块、商品模块。
fixed 404 bug
http://localhost:7001/product
// router.get('/', controller.product.index);
router.get('/product', controller.product.index);
koa 洋葱模型
koa 中间件
app的类型是Egg.Application,是全局应用对象,在每个项目中只会实例化一次,也就是说egg.js默认把router,controller集成好了。
controller里放置个个业务模块;
egg.js使用规范:文件名小写,类名首字母大写并使用驼峰命名;
egg.js框架中使用同步编程模式=> async...await;
ctx每次用户在使用时,框架就会实例化的一个Egg.content上下文,content用来存放用户请求的一些信息;