Files
claude-relay-service/config/config.example.js

118 lines
4.0 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.

const path = require('path');
require('dotenv').config();
const config = {
// 🌐 服务器配置
server: {
port: parseInt(process.env.PORT) || 3000,
host: process.env.HOST || '0.0.0.0',
nodeEnv: process.env.NODE_ENV || 'development',
trustProxy: process.env.TRUST_PROXY === 'true'
},
// 🔐 安全配置
security: {
jwtSecret: process.env.JWT_SECRET || 'CHANGE-THIS-JWT-SECRET-IN-PRODUCTION',
adminSessionTimeout: parseInt(process.env.ADMIN_SESSION_TIMEOUT) || 86400000, // 24小时
apiKeyPrefix: process.env.API_KEY_PREFIX || 'cr_',
encryptionKey: process.env.ENCRYPTION_KEY || 'CHANGE-THIS-32-CHARACTER-KEY-NOW'
},
// 📊 Redis配置
redis: {
host: process.env.REDIS_HOST || '127.0.0.1',
port: parseInt(process.env.REDIS_PORT) || 6379,
password: process.env.REDIS_PASSWORD || '',
db: parseInt(process.env.REDIS_DB) || 0,
connectTimeout: 10000,
commandTimeout: 5000,
retryDelayOnFailover: 100,
maxRetriesPerRequest: 3,
lazyConnect: true,
enableTLS: process.env.REDIS_ENABLE_TLS === 'true',
},
// 🎯 Claude API配置
claude: {
apiUrl: process.env.CLAUDE_API_URL || 'https://api.anthropic.com/v1/messages',
apiVersion: process.env.CLAUDE_API_VERSION || '2023-06-01',
betaHeader: process.env.CLAUDE_BETA_HEADER || 'claude-code-20250219,oauth-2025-04-20,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14'
},
// 🌐 代理配置
proxy: {
timeout: parseInt(process.env.DEFAULT_PROXY_TIMEOUT) || 30000,
maxRetries: parseInt(process.env.MAX_PROXY_RETRIES) || 3
},
// 📈 使用限制
limits: {
defaultTokenLimit: parseInt(process.env.DEFAULT_TOKEN_LIMIT) || 1000000
},
// 📝 日志配置
logging: {
level: process.env.LOG_LEVEL || 'info',
dirname: path.join(__dirname, '..', 'logs'),
maxSize: process.env.LOG_MAX_SIZE || '10m',
maxFiles: parseInt(process.env.LOG_MAX_FILES) || 5
},
// 🔧 系统配置
system: {
cleanupInterval: parseInt(process.env.CLEANUP_INTERVAL) || 3600000, // 1小时
tokenUsageRetention: parseInt(process.env.TOKEN_USAGE_RETENTION) || 2592000000, // 30天
healthCheckInterval: parseInt(process.env.HEALTH_CHECK_INTERVAL) || 60000, // 1分钟
timezone: process.env.SYSTEM_TIMEZONE || 'Asia/Shanghai', // 默认UTC+8中国时区
timezoneOffset: parseInt(process.env.TIMEZONE_OFFSET) || 8 // UTC偏移小时数默认+8
},
// 🎨 Web界面配置
web: {
title: process.env.WEB_TITLE || 'Claude Relay Service',
description: process.env.WEB_DESCRIPTION || 'Multi-account Claude API relay service with beautiful management interface',
logoUrl: process.env.WEB_LOGO_URL || '/assets/logo.png',
enableCors: process.env.ENABLE_CORS === 'true',
sessionSecret: process.env.WEB_SESSION_SECRET || 'CHANGE-THIS-SESSION-SECRET'
},
// 🔒 客户端限制配置
clientRestrictions: {
// 预定义的客户端列表
predefinedClients: [
{
id: 'claude_code',
name: 'ClaudeCode',
description: 'Official Claude Code CLI',
// 匹配 Claude CLI 的 User-Agent
// 示例: claude-cli/1.0.58 (external, cli)
userAgentPattern: /^claude-cli\/[\d\.]+\s+\(/i
},
{
id: 'gemini_cli',
name: 'Gemini-CLI',
description: 'Gemini Command Line Interface',
// 匹配 GeminiCLI 的 User-Agent
// 示例: GeminiCLI/v18.20.8 (darwin; arm64)
userAgentPattern: /^GeminiCLI\/v?[\d\.]+\s+\(/i
}
// 添加自定义客户端示例:
// {
// id: 'custom_client',
// name: 'My Custom Client',
// description: 'My custom API client',
// userAgentPattern: /^MyClient\/[\d\.]+/i
// }
],
// 是否允许自定义客户端(未来功能)
allowCustomClients: process.env.ALLOW_CUSTOM_CLIENTS === 'true'
},
// 🛠️ 开发配置
development: {
debug: process.env.DEBUG === 'true',
hotReload: process.env.HOT_RELOAD === 'true'
}
};
module.exports = config;