mirror of
https://github.com/lobehub/lobehub
synced 2026-04-21 17:47:27 +00:00
🐛 fix: message gateway ensure running (#13780)
fix: message gateway ensure running
This commit is contained in:
parent
7953cf5b5a
commit
809e1e0716
2 changed files with 10 additions and 8 deletions
|
|
@ -123,11 +123,13 @@ export async function GET(request: NextRequest) {
|
|||
return new Response('Unauthorized', { status: 401 });
|
||||
}
|
||||
|
||||
// When an external message gateway is fully configured (both URL and service
|
||||
// token), it manages all persistent connections. Skip in-process bot startup
|
||||
// to avoid duplicate connections.
|
||||
// When an external message gateway is configured, use ensureRunning to sync
|
||||
// connections via the gateway instead of starting bots in-process.
|
||||
if (process.env.MESSAGE_GATEWAY_URL && process.env.MESSAGE_GATEWAY_SERVICE_TOKEN) {
|
||||
return Response.json({ skipped: true, reason: 'using external message gateway' });
|
||||
const { GatewayService } = await import('@/server/services/gateway');
|
||||
const service = new GatewayService();
|
||||
await service.ensureRunning();
|
||||
return Response.json({ ensureRunning: true, reason: 'synced via external message gateway' });
|
||||
}
|
||||
|
||||
const platforms = platformRegistry.listPlatforms();
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@ export async function register() {
|
|||
await import('./libs/debug-file-logger');
|
||||
}
|
||||
|
||||
// Auto-start GatewayManager / sync message-gateway connections on server start.
|
||||
// - Non-Vercel (Docker, local): always run — persistent bots need reconnection after restart.
|
||||
// - Vercel: only run when an external message gateway is configured, to sync connection state.
|
||||
// Auto-start GatewayManager on server start for non-Vercel environments (Docker, local).
|
||||
// Persistent bots need reconnection after restart.
|
||||
// On Vercel, the cron job at /api/agent/gateway handles this reliably instead.
|
||||
if (
|
||||
process.env.NEXT_RUNTIME === 'nodejs' &&
|
||||
process.env.DATABASE_URL &&
|
||||
(!process.env.VERCEL_ENV || process.env.MESSAGE_GATEWAY_URL)
|
||||
!process.env.VERCEL_ENV
|
||||
) {
|
||||
const { GatewayService } = await import('./server/services/gateway');
|
||||
const service = new GatewayService();
|
||||
|
|
|
|||
Loading…
Reference in a new issue