config.js 916 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * 应用全局配置文件
  3. */
  4. // 环境变量
  5. const ENV = process.env.NODE_ENV || 'development';
  6. // 应用配置
  7. const config = {
  8. // 通用配置
  9. common: {
  10. port: process.env.PORT || 3000,
  11. sessionSecret: process.env.SESSION_SECRET || 'OhTq3faqSKoxbV%NJV',
  12. logLevel: process.env.LOG_LEVEL || 'info'
  13. },
  14. // 开发环境配置
  15. development: {
  16. debug: true,
  17. cors: {
  18. origin: '*',
  19. credentials: true
  20. },
  21. secureSession: false
  22. },
  23. // 生产环境配置
  24. production: {
  25. debug: false,
  26. cors: {
  27. origin: 'https://yourdomain.com',
  28. credentials: true
  29. },
  30. secureSession: true
  31. },
  32. // 测试环境配置
  33. test: {
  34. debug: true,
  35. cors: {
  36. origin: '*',
  37. credentials: true
  38. },
  39. secureSession: false,
  40. port: 3001
  41. }
  42. };
  43. // 导出合并后的配置
  44. module.exports = {
  45. ...config.common,
  46. ...config[ENV],
  47. env: ENV
  48. };