(server)
| 2403 | apply: 'serve', |
| 2404 | |
| 2405 | configureServer(server) { |
| 2406 | pluginRoot = (server as any).config?.root || process.cwd(); |
| 2407 | const httpServer = server.httpServer; |
| 2408 | if (!httpServer) return; |
| 2409 | |
| 2410 | // Attempt early vendor manifest bootstrap once per server. |
| 2411 | if (!vendorBootstrapDone) { |
| 2412 | vendorBootstrapDone = true; |
| 2413 | const root = (server as any).config?.root || process.cwd(); |
| 2414 | const existing = getVendorManifest(); |
| 2415 | if (!existing) { |
| 2416 | const loaded = loadPrebuiltVendorManifest(root, verbose); |
| 2417 | if (!loaded && verbose) { |
| 2418 | console.warn('[hmr-ws][vendor] No vendor manifest found during bootstrap. Consider enabling vendorManifestPlugin earlier.'); |
| 2419 | } |
| 2420 | } else if (verbose) { |
| 2421 | console.log('[hmr-ws][vendor] Manifest already present with', Object.keys(existing.modules).length, 'modules'); |
| 2422 | } |
| 2423 | (globalThis as any).__NS_VENDOR_MANIFEST__ = getVendorManifest(); |
| 2424 | } |
| 2425 | |
| 2426 | // Disable perMessageDeflate to avoid any extension negotiation quirks with native clients |
| 2427 | wss = new WebSocketServer({ |
| 2428 | noServer: true, |
| 2429 | path: '/ns-hmr', |
| 2430 | perMessageDeflate: false, |
| 2431 | }); |
| 2432 | |
| 2433 | if (verbose) { |
| 2434 | console.log('[hmr-ws] WebSocket configured on /ns-hmr'); |
| 2435 | } |
| 2436 | |
| 2437 | httpServer.on('upgrade', (request, socket, head) => { |
| 2438 | try { |
| 2439 | if (verbose) { |
| 2440 | const ra = (request.socket as any)?.remoteAddress; |
| 2441 | const rp = (request.socket as any)?.remotePort; |
| 2442 | console.log('[hmr-ws][upgrade]', request.url, 'from', ra + (rp ? ':' + rp : '')); |
| 2443 | } |
| 2444 | } catch {} |
| 2445 | const pathname = new URL(request.url || '', 'http://localhost').pathname; |
| 2446 | if (pathname === '/ns-hmr') { |
| 2447 | wss?.handleUpgrade(request, socket, head, (ws) => { |
| 2448 | wss?.emit('connection', ws, request); |
| 2449 | }); |
| 2450 | } |
| 2451 | }); |
| 2452 | |
| 2453 | // Additional connection diagnostics |
| 2454 | wss.on('connection', (ws, req) => { |
| 2455 | try { |
| 2456 | if (verbose) { |
| 2457 | const ra = (req.socket as any)?.remoteAddress; |
| 2458 | const rp = (req.socket as any)?.remotePort; |
| 2459 | console.log('[hmr-ws] Client connected', ra + (rp ? ':' + rp : '')); |
| 2460 | } |
| 2461 | } catch {} |
| 2462 | }); |
nothing calls this directly
no test coverage detected