Alexlz2538/egg-plugins

egg 插件

★ 0Forks 0TypeScriptGitHub ↗Compare

README

mito-egg

egg 中间件

egg-gzip

npm i egg-gzip 或者yarn add egg-gzip

启动

// plugin.ts
const plugin = {
  //...
  gzip: {
    enable: true, 
    package: 'egg-gzip',
  },
};

配置

// config.default.[jt]s
export default = ()=>{
  //...
  const confg = {};
  config.gzip: {
    threshold: 1024, // 小于 1k 的响应体不压缩
  },
  //...
  return {
    ...config,
  }
}

egg-mockjs

用于模拟数据,依赖mockjs,可以使用mockjs生成随机数据

npm i egg-mockjs 或者yarn add egg-mockjs

启动

// plugin.ts
const plugin = {
  //...
  mockjs: {
    enable: true,
    package: 'egg-mockjs',
  },
};

使用

// root/app/mock/demo.ts
export default {
  // 支持值为 Object 和 Array
  'GET /api/users': { users: [1, 2] },

  // GET POST 可省略
  '/api/users/1': { id: 1 },

  // 支持自定义函数,API 参考 koa
  'POST /api/users/create': (ctx) => { ctx.body = 'ok';},
};

Contributors

Alexlz2538

Issues