parent
63b4f679f1
commit
8bcd039e9d
@ -1,32 +1,80 @@
|
||||
import dotenv from 'dotenv';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
// 从文件读取配置
|
||||
let fileConfig = {};
|
||||
try {
|
||||
const configPath = path.join(__dirname, '../../../config.json');
|
||||
if (fs.existsSync(configPath)) {
|
||||
const configData = fs.readFileSync(configPath, 'utf8');
|
||||
fileConfig = JSON.parse(configData);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('读取配置文件失败:', error);
|
||||
}
|
||||
|
||||
export const config = {
|
||||
port: process.env.PORT || 3005,
|
||||
jwtSecret: process.env.JWT_SECRET || 'your-secret-key',
|
||||
port: process.env.PORT || (fileConfig.server?.port || 3005),
|
||||
jwtSecret: process.env.JWT_SECRET || (fileConfig.security?.jwtSecret || 'your-secret-key'),
|
||||
database: {
|
||||
mongo: {
|
||||
url: process.env.MONGO_URL || 'mongodb://localhost:27017/alpha-futures'
|
||||
},
|
||||
postgres: {
|
||||
host: process.env.PG_HOST || 'localhost',
|
||||
port: parseInt(process.env.PG_PORT || '5432'),
|
||||
user: process.env.PG_USER || 'postgres',
|
||||
password: process.env.PG_PASSWORD || 'password',
|
||||
database: process.env.PG_DATABASE || 'alpha-futures'
|
||||
host: process.env.PG_HOST || (fileConfig.database?.postgreSQL?.host || 'localhost'),
|
||||
port: parseInt(process.env.PG_PORT || (fileConfig.database?.postgreSQL?.port || '5432')),
|
||||
user: process.env.PG_USER || (fileConfig.database?.postgreSQL?.username || 'postgres'),
|
||||
password: process.env.PG_PASSWORD || (fileConfig.database?.postgreSQL?.password || 'password'),
|
||||
database: process.env.PG_DATABASE || (fileConfig.database?.postgreSQL?.database || 'alpha-futures')
|
||||
}
|
||||
},
|
||||
redis: {
|
||||
url: process.env.REDIS_URL || 'redis://localhost:6379'
|
||||
},
|
||||
rateLimit: {
|
||||
windowMs: 60 * 1000, // 1分钟
|
||||
max: 120 // 每分钟120次请求
|
||||
windowMs: fileConfig.security?.rateLimit?.windowMs || 60 * 1000, // 1分钟
|
||||
max: fileConfig.security?.rateLimit?.max || 120 // 每分钟120次请求
|
||||
},
|
||||
cors: {
|
||||
origin: '*', // 在生产环境中应该设置具体的域名
|
||||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
||||
allowedHeaders: ['Content-Type', 'Authorization']
|
||||
origin: fileConfig.security?.cors?.origin || '*', // 在生产环境中应该设置具体的域名
|
||||
methods: fileConfig.security?.cors?.methods || ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
||||
allowedHeaders: fileConfig.security?.cors?.allowedHeaders || ['Content-Type', 'Authorization']
|
||||
},
|
||||
dataSource: fileConfig.dataSource || {
|
||||
test: {
|
||||
enabled: true,
|
||||
timeout: 10000,
|
||||
retries: 3,
|
||||
refreshInterval: 60000
|
||||
},
|
||||
tqsdk: {
|
||||
enabled: true,
|
||||
apiKey: '',
|
||||
apiSecret: '',
|
||||
username: '',
|
||||
password: '',
|
||||
timeout: 30000,
|
||||
retries: 3,
|
||||
maxConnections: 5
|
||||
},
|
||||
wind: {
|
||||
enabled: false,
|
||||
apiKey: '',
|
||||
apiSecret: '',
|
||||
url: 'https://api.wind.com.cn',
|
||||
timeout: 30000,
|
||||
retries: 3
|
||||
},
|
||||
sina: {
|
||||
enabled: false,
|
||||
url: 'https://finance.sina.com.cn',
|
||||
timeout: 10000,
|
||||
retries: 3,
|
||||
refreshInterval: 60000
|
||||
},
|
||||
defaultDataSource: 'tqsdk'
|
||||
}
|
||||
};
|
||||
Loading…
Reference in new issue