eggjs提供了统一的入口文件 app.js;可以在启动的过程中,自定义需要执行的任务或方法
/app.js
'use strict';module.exports = app => {require('module-alias/register');// beforeStart 执行在 Controller之后app.beforeStart(async () => {// await require('module-alias/register');});// 将 session保存到内存中const store = {};app.sessionStore = {async get(key) {return store[key];},async set(key, value, maxAge) {store[key] = value;store.maxAge = maxAge;},async destroy(key) {store[key] = null;},};// 将 plugin插件放入数组中// const { coreMiddleware } = app.config;// const plugins = [// 'notFound', 'auth',// ];// app.config.coreMiddleware = [// ...coreMiddleware,// ...plugins,// ];// app.config.coreMiddleware.push('auth');// app.beforeClose(async () => {});};
