const config = require('../config.json') const VALID_ROLES = new Set(['all', 'api', 'worker']) /** * 进程角色:all=API+乐跑Worker一体;api=仅HTTP入队;worker=仅消费乐跑任务 * 环境变量 RUNFORGE_SERVER_ROLE 优先于 config.serverRole */ function resolveServerRole() { const raw = process.env.RUNFORGE_SERVER_ROLE || config.serverRole || 'all' const role = String(raw).toLowerCase() if (VALID_ROLES.has(role)) return role console.warn(`[serverRole] 未知值 "${raw}",回退为 all`) return 'all' } function shouldServeApi(role) { return role === 'all' || role === 'api' } function shouldRunLepaoWorker(role) { return role === 'all' || role === 'worker' } module.exports = { resolveServerRole, shouldServeApi, shouldRunLepaoWorker }