config.default.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
  2. import * as path from 'path';
  3. import * as fs from 'fs';
  4. export default (appInfo: EggAppInfo) => {
  5. const config = {} as PowerPartial<EggAppConfig>;
  6. // override config from framework / plugin
  7. // use for cookie sign key, should change to your own and keep security
  8. config.keys = appInfo.name + '_1597893009804_8539';
  9. // 配置网站图标 可为网络图标
  10. config.siteFile = {
  11. '/favicon.ico': fs.readFileSync(path.join(__dirname, '../favicon.ico')),
  12. };
  13. // add your egg config in here
  14. config.middleware = [ 'adminReqLog', 'execption', 'adminAuthority' ];
  15. config.aesSecret = {
  16. admin: 'hXuLvp6zmhahtW1kf21DpYxm',
  17. front: 'eECRYHR5Er93BijVlkMz9CIn',
  18. };
  19. config.jwt = {
  20. secret: 'INnyQ50BEE6AITQraIaDGooJ',
  21. };
  22. // Root角色对应ID
  23. config.rootRoleId = 1;
  24. /**
  25. * 框架内置了国际化(I18n)支持,由 egg-i18n 插件提供。
  26. * 更多配置参考 @{Link:https://github.com/eggjs/egg-i18n}
  27. */
  28. config.i18n = {
  29. defaultLocale: 'zh-CN',
  30. };
  31. // add your special config in here
  32. const bizConfig = {
  33. sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
  34. };
  35. // https://eggjs.org/zh-cn/core/security.html
  36. config.security = {
  37. // 配合egg-cors使用
  38. // domainWhiteList: [ 'http://localhost:7003' ],
  39. csrf: {
  40. // 默认为 false,当设置为 true 时,将会放过所有 content-type 为 `application/json` 的请求
  41. enable: false,
  42. ignoreJSON: true,
  43. },
  44. };
  45. /**
  46. * egg-global-header
  47. * https://github.com/eggjs/egg-global-header
  48. */
  49. config.globalHeader = {
  50. 'Powered-by': 'sf-admin',
  51. };
  52. /**
  53. * CORS
  54. * https://github.com/eggjs/egg-cors
  55. */
  56. config.cors = {
  57. // origin: '*',
  58. allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
  59. };
  60. // 模板渲染配置
  61. config.view = {
  62. defaultViewEngine: 'nunjucks',
  63. };
  64. // static config
  65. config.static = {
  66. prefix: '/static/',
  67. dir: path.join(appInfo.baseDir, 'public'),
  68. dynamic: true,
  69. preload: false,
  70. // maxAge: 31536000,
  71. maxAge: 0,
  72. buffer: false,
  73. };
  74. /**
  75. * https://eggjs.org/zh-cn/basics/controller.html#获取上传的文件
  76. */
  77. config.multipart = {
  78. mode: 'file',
  79. };
  80. // https://eggjs.org/zh-cn/core/error-handling.html
  81. config.onerror = {
  82. // all(err: any, ctx: any) {
  83. // // 在此处定义针对所有响应类型的错误处理方法
  84. // // 注意,定义了 config.all 之后,其他错误处理方法不会再生效
  85. // ctx.set('Content-Type', 'application/json');
  86. // // 生产环境时 500 错误的详细错误内容不返回给客户端,因为可能包含敏感信息
  87. // const status = err.status || 500;
  88. // const message = status === 500 && ctx.app.config.env === 'prod' ? 'Server internal exception, please try again later' : err.message;
  89. // ctx.body = JSON.stringify({
  90. // errorCode: err.errorCode || 500,
  91. // message,
  92. // });
  93. // },
  94. };
  95. // the return config will combines to EggAppConfig
  96. return {
  97. ...config,
  98. ...bizConfig,
  99. };
  100. };