config.default.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
  2. // import * as process from 'process';
  3. require('dotenv').config(); // 加载dotenv配置文件用于支持 env
  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.security = {
  9. csrf: {
  10. enable: process.env.SECURITY_CSRF ? process.env.SECURITY_CSRF === 'true' : true,
  11. ignoreJSON: true,
  12. },
  13. domainWhiteList: [ 'http://localhost:8080', '*' ],
  14. };
  15. config.keys = appInfo.name + process.env.SECURITY_KEY || '_1687254724720_1708';
  16. // add your egg config in here
  17. config.middleware = [];
  18. // add your special config in here
  19. const bizConfig = {
  20. sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
  21. };
  22. config.jwt = {
  23. secret: process.env.JWT_KEY ? process.env.JWT_KEY : 'admin@zhangp.cn',
  24. };
  25. config.cors = {
  26. origin: '*',
  27. allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
  28. };
  29. // the return config will combines to EggAppConfig
  30. return {
  31. ...config,
  32. ...bizConfig,
  33. };
  34. };
  35. // 数据库链接
  36. exports.sequelize = {
  37. dialect: 'mysql',
  38. host: process.env.DATABASE_HOST || '192.168.2.254',
  39. port: process.env.DATABASE_PORT || 3306,
  40. database: process.env.DATABASE_DATABASE || 'test_egg',
  41. username: process.env.DATABASE_USERNAME || 'test_egg',
  42. password: process.env.DATABASE_PWD || '123456',
  43. underscored: true,
  44. timezone: process.env.TZ || '+UTC',
  45. pool: {
  46. max: 5,
  47. min: 0,
  48. acquire: 30000,
  49. idle: 10000,
  50. },
  51. };