oms/backend/config/config.default.js

119 lines
3.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
// 加载项目根目录 .env(敏感配置不入库);文件不存在时自动忽略
require('dotenv').config();
const db = require('../database/config').development;
/**
* @param {Egg.EggAppInfo} appInfo app info
*/
module.exports = appInfo => {
/**
* built-in config
* @type {Egg.EggAppConfig}
**/
const config = exports = {};
// use for cookie sign key, should change to your own and keep security
config.keys = appInfo.name + '_1720000000000_1234';
// 全局中间件:requestLog 记录请求日志(洋葱模型,在响应阶段读取用户信息)
config.middleware = [ 'requestLog' ];
// 请求日志配置
config.requestLog = {
keepDays: Number(process.env.REQUEST_LOG_KEEP_DAYS || 60),
maxBodyLength: Number(process.env.REQUEST_LOG_MAX_BODY || 2000),
// 不记录的路径前缀(Swagger 静态资源等)
excludePaths: [ '/swagger' ],
};
// close csrf for easy debugging, please enable it in production if needed
config.security = {
csrf: {
enable: false,
},
};
// sequelize / mysql config,与 sequelize-cli 迁移共用 database/config.js
config.sequelize = {
...db,
define: {
underscored: true,
charset: 'utf8mb4',
dialectOptions: {
collate: 'utf8mb4_unicode_ci',
},
},
pool: {
max: 10,
min: 0,
idle: 10000,
},
};
// 邮件发送(SMTP)配置:未配置 SMTP_HOST 时验证码仅输出到日志,便于本地调试
config.mailer = {
host: process.env.SMTP_HOST || '',
port: Number(process.env.SMTP_PORT || 465),
secure: process.env.SMTP_SECURE !== 'false',
auth: {
user: process.env.SMTP_USER || '',
pass: process.env.SMTP_PASS || '',
},
from: process.env.SMTP_FROM || 'noreply@oms.local',
};
// Redis 配置:缓存邮箱验证码等数据,敏感信息建议用环境变量覆盖
config.redis = {
client: {
host: process.env.REDIS_HOST || '127.0.0.1',
port: Number(process.env.REDIS_PORT || 6379),
password: process.env.REDIS_PASSWORD || 'qwe2019',
db: 0,
},
};
// 邮箱验证码限流:同一邮箱发送间隔(秒)与每日发送上限
config.emailCode = {
interval: Number(process.env.EMAIL_CODE_INTERVAL || 60),
dailyLimit: Number(process.env.EMAIL_CODE_DAILY_LIMIT || 10),
};
// JWT 配置:secret 必须通过环境变量 JWT_SECRET 覆盖,切勿使用默认值上生产
config.jwt = {
secret: process.env.JWT_SECRET || 'oms-dev-jwt-secret-change-me',
expiresIn: process.env.JWT_EXPIRES_IN || '2h',
};
// swagger 文档:UI 访问 /swagger-ui.html,JSON 访问 /swagger-doc
config.swaggerdoc = {
dirScanner: './app/controller',
basePath: '/',
apiInfo: {
title: 'OMS API',
description: 'OMS 后端接口文档',
version: '1.0.0',
},
schemes: [ 'http', 'https' ],
consumes: [ 'application/json' ],
produces: [ 'application/json' ],
securityDefinitions: {
apikey: {
type: 'apiKey',
name: 'Authorization',
in: 'header',
},
},
enableSecurity: true,
routerMap: false,
// 生产环境关闭文档
enable: appInfo.env !== 'prod',
};
return {
...config,
};
};