config.default.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* eslint valid-jsdoc: "off" */
  2. 'use strict';
  3. const path = require('path');
  4. /**
  5. * @param {Egg.EggAppInfo} appInfo app info
  6. */
  7. module.exports = appInfo => {
  8. /**
  9. * built-in config
  10. * @type {Egg.EggAppConfig}
  11. **/
  12. const config = {};
  13. // use for cookie sign key, should change to your own and keep security
  14. config.keys = appInfo.name + '_1552879336505_7432';
  15. // add your middleware config here
  16. config.middleware = [];
  17. // add your user config here
  18. const userConfig = {
  19. // myAppName: 'egg',
  20. };
  21. config.cluster = {
  22. listen: {
  23. port: 7068,
  24. hostname: '0.0.0.0',
  25. // path: '/var/run/egg.sock',
  26. },
  27. };
  28. // jwt插件配置(盐)
  29. config.jwt = {
  30. secret: 'jcgame88',
  31. };
  32. /* 跨域插件配置-start */
  33. config.security = {
  34. xframe: {
  35. enable: false,
  36. },
  37. ignore: '/api',
  38. // 跨域允许的域名列表-配置
  39. domainWhiteList: [
  40. '*',
  41. // 'http://127.0.0.1:8080'
  42. ],
  43. methodnoallow: { enable: false },
  44. // 安全配置(很重要)
  45. csrf: {
  46. enable: false,
  47. ignoreJSON: true, // 默认为 false,当设置为 true 时,将会放过所有 content-type 为 `application/json` 的请求
  48. },
  49. };
  50. // 允许的跨域请求类型(GET,POST)
  51. config.cors = {
  52. origin: '*',
  53. // allowMethods: 'GET,POST',
  54. allowMethods: 'GET,POST,HEAD,PUT,OPTIONS,DELETE,PATCH',
  55. };
  56. /* 跨域插件配置-end */
  57. // 校验插件配置(支持 parameter的所有配置项)
  58. config.validate = {
  59. // convert: false,
  60. // validateRoot: false,
  61. };
  62. // 获取真实ip
  63. config.maxProxyCount = 2;
  64. config.view = {
  65. root: [path.join(appInfo.baseDir, 'app/view')].join(','),
  66. mapping: {
  67. '.ejs': 'ejs',
  68. },
  69. };
  70. config.static = {
  71. // 静态化访问前缀,如:`http://127.0.0.1:7001/static/images/logo.png`
  72. prefix: '/',
  73. dir: [path.join(appInfo.baseDir, 'app/public')], // `String` or `Array:[dir1, dir2, ...]` 静态化目录,可以设置多个静态化目录
  74. dynamic: true, // 如果当前访问的静态资源没有缓存,则缓存静态文件,和`preload`配合使用;
  75. preload: false,
  76. maxAge: 31536000, // in prod env, 0 in other envs
  77. buffer: true, // in prod env, false in other envs
  78. };
  79. config.ejs = {};
  80. return {
  81. ...config,
  82. ...userConfig,
  83. };
  84. };