config.default.js 2.4 KB

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