86b06dc417
- api/websocket: capture asynchrone EADDRINUSE pour ne pas bloquer le build - proxy: réécrit aussi les URLs protocol-relatives (//localhost) dans le corps
24 lines
759 B
TypeScript
24 lines
759 B
TypeScript
import { WebSocketServer } from "ws";
|
|
import { initWebSocketServer } from "@/lib/websocket";
|
|
|
|
const globalWss = globalThis as typeof globalThis & { __eduboxWss?: WebSocketServer };
|
|
|
|
if (!globalWss.__eduboxWss) {
|
|
try {
|
|
const wss = new WebSocketServer({ port: 3001 });
|
|
wss.on("error", (err) => {
|
|
// Silently ignore EADDRINUSE during build/hot reload; the existing
|
|
// server will keep handling agent connections.
|
|
console.warn("WebSocket server error:", (err as Error).message);
|
|
});
|
|
globalWss.__eduboxWss = wss;
|
|
initWebSocketServer(wss);
|
|
} catch {
|
|
// Port may be in use during build or hot reload
|
|
}
|
|
}
|
|
|
|
export async function GET() {
|
|
return new Response("WebSocket server running on port 3001", { status: 200 });
|
|
}
|