egg 项目实战(二)初始Egg.js中的路由

1.创建 product 控制器

app/controller/product.js

const Controller = require('egg').Controller;

class ProductController extends Controller {
    async index() {
        /**
         * ctx 主要用来存储用户请求的信息
         * 每次请求时都会实例化
         */
        const { ctx } = this;
        ctx.body = 'product';
    }
}

module.exports = ProductController;

2.添加路由

原文地址:https://www.cnblogs.com/crazycode2/p/12421878.html