fix: register @fastify/websocket globally so /ws/agent route works

setupAgentWsRoute was called outside the encapsulated wsRoutes plugin
scope where @fastify/websocket was registered. Register the plugin at
the root level and convert setupAgentWsRoute to FastifyPluginAsync.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-27 12:20:28 +03:00
parent ee7ee78c5d
commit c5413566dd
3 changed files with 7 additions and 6 deletions

View File

@@ -10,6 +10,7 @@ import { join } from 'path'
import { config } from './config'
import './types' // side-effect: augments fastify types
import fastifyWebsocket from '@fastify/websocket'
import wsRoutes from './routes/ws'
import authRoutes from './routes/auth'
import hotelsRoutes from './routes/hotels'
@@ -53,6 +54,9 @@ export async function buildApp() {
const uploadsDir = process.env.UPLOADS_DIR ?? join(process.cwd(), 'uploads')
await fastify.register(staticFiles, { root: uploadsDir, prefix: '/uploads/' })
// ── WebSocket ──────────────────────────────────────────────────────────────
await fastify.register(fastifyWebsocket)
// ── Security ───────────────────────────────────────────────────────────────
await fastify.register(helmet, { contentSecurityPolicy: false, crossOriginResourcePolicy: { policy: 'cross-origin' } })
@@ -114,7 +118,7 @@ export async function buildApp() {
await fastify.register(loyaltyRoutes)
await fastify.register(chatRoutes)
await fastify.register(workstationRoutes)
setupAgentWsRoute(fastify)
await fastify.register(setupAgentWsRoute)
startJobs()