parent
63b4f679f1
commit
8bcd039e9d
@ -1,32 +1,80 @@
|
|||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
dotenv.config();
|
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 = {
|
export const config = {
|
||||||
port: process.env.PORT || 3005,
|
port: process.env.PORT || (fileConfig.server?.port || 3005),
|
||||||
jwtSecret: process.env.JWT_SECRET || 'your-secret-key',
|
jwtSecret: process.env.JWT_SECRET || (fileConfig.security?.jwtSecret || 'your-secret-key'),
|
||||||
database: {
|
database: {
|
||||||
mongo: {
|
mongo: {
|
||||||
url: process.env.MONGO_URL || 'mongodb://localhost:27017/alpha-futures'
|
url: process.env.MONGO_URL || 'mongodb://localhost:27017/alpha-futures'
|
||||||
},
|
},
|
||||||
postgres: {
|
postgres: {
|
||||||
host: process.env.PG_HOST || 'localhost',
|
host: process.env.PG_HOST || (fileConfig.database?.postgreSQL?.host || 'localhost'),
|
||||||
port: parseInt(process.env.PG_PORT || '5432'),
|
port: parseInt(process.env.PG_PORT || (fileConfig.database?.postgreSQL?.port || '5432')),
|
||||||
user: process.env.PG_USER || 'postgres',
|
user: process.env.PG_USER || (fileConfig.database?.postgreSQL?.username || 'postgres'),
|
||||||
password: process.env.PG_PASSWORD || 'password',
|
password: process.env.PG_PASSWORD || (fileConfig.database?.postgreSQL?.password || 'password'),
|
||||||
database: process.env.PG_DATABASE || 'alpha-futures'
|
database: process.env.PG_DATABASE || (fileConfig.database?.postgreSQL?.database || 'alpha-futures')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
redis: {
|
redis: {
|
||||||
url: process.env.REDIS_URL || 'redis://localhost:6379'
|
url: process.env.REDIS_URL || 'redis://localhost:6379'
|
||||||
},
|
},
|
||||||
rateLimit: {
|
rateLimit: {
|
||||||
windowMs: 60 * 1000, // 1分钟
|
windowMs: fileConfig.security?.rateLimit?.windowMs || 60 * 1000, // 1分钟
|
||||||
max: 120 // 每分钟120次请求
|
max: fileConfig.security?.rateLimit?.max || 120 // 每分钟120次请求
|
||||||
},
|
},
|
||||||
cors: {
|
cors: {
|
||||||
origin: '*', // 在生产环境中应该设置具体的域名
|
origin: fileConfig.security?.cors?.origin || '*', // 在生产环境中应该设置具体的域名
|
||||||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
methods: fileConfig.security?.cors?.methods || ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
||||||
allowedHeaders: ['Content-Type', 'Authorization']
|
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