config.default.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. 'use strict';
  2. const path = require('path');
  3. const Utils = require('ee-core').Utils;
  4. const eggConfig = Utils.getEggConfig();
  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. config.cluster = {
  21. listen: {
  22. port: eggConfig.port || 7068,
  23. hostname: eggConfig.hostname || '127.0.0.1',
  24. },
  25. };
  26. /* 跨域插件配置-start */
  27. config.security = {
  28. xframe: {
  29. enable: false,
  30. },
  31. ignore: '/api',
  32. // 跨域允许的域名列表-配置
  33. domainWhiteList: [
  34. '*',
  35. // 'http://127.0.0.1:8080'
  36. ],
  37. methodnoallow: { enable: false },
  38. // 安全配置
  39. csrf: {
  40. enable: false,
  41. ignoreJSON: true, // 默认为 false,当设置为 true 时,将会放过所有 content-type 为 `application/json` 的请求
  42. },
  43. };
  44. // 允许的跨域请求类型(GET,POST)
  45. config.cors = {
  46. origin: '*',
  47. allowMethods: 'GET,POST,HEAD,PUT,OPTIONS,DELETE,PATCH',
  48. };
  49. /* 跨域插件配置-end */
  50. // 获取真实ip
  51. config.maxProxyCount = 2;
  52. config.view = {
  53. root: [path.join(appInfo.baseDir, 'app/view')].join(','),
  54. mapping: {
  55. '.ejs': 'ejs',
  56. },
  57. };
  58. config.static = {
  59. // 静态化访问前缀,如:`http://127.0.0.1:7001/static/images/logo.png`
  60. prefix: '/',
  61. dir: [path.join(appInfo.baseDir, 'app/public')], // `String` or `Array:[dir1, dir2, ...]` 静态化目录,可以设置多个静态化目录
  62. dynamic: true, // 如果当前访问的静态资源没有缓存,则缓存静态文件,和`preload`配合使用;
  63. preload: false,
  64. maxAge: 31536000, // in prod env, 0 in other envs
  65. buffer: true, // in prod env, false in other envs
  66. };
  67. config.ejs = {};
  68. config.multipart = {
  69. mode: 'file',
  70. fileExtensions: [ '.xlsx', '.crx' ] // 增加你需要的文件扩展名
  71. };
  72. return {
  73. ...config,
  74. ...userConfig,
  75. };
  76. };