fix(api): WS gateways crashed on first forwarded event — WebSocket.OPEN undefined at runtime
Lesson 10 in the flesh: the onApplicationBootstrap fix made the NATS-> WS bridge actually deliver events for the first time, which instantly crashed the API. esModuleInterop is off, so 'import WebSocket from ws' compiles to ws_1.default = undefined; WebSocket.OPEN threw 'Cannot read properties of undefined' and killed the process on the first heartbeat forward. All three WS guard sites (nats-bridge x2, console gateway) switched to the import-agnostic instance constant client.OPEN. Latent in every build — never hit because the bridge was dead-on-boot until today. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -71,7 +71,10 @@ export class NatsBridgeGateway implements OnGatewayConnection, OnGatewayDisconne
|
|||||||
|
|
||||||
// Subscribe to NATS events for this license
|
// Subscribe to NATS events for this license
|
||||||
const listener = (event: string, data: unknown) => {
|
const listener = (event: string, data: unknown) => {
|
||||||
if (client.readyState === WebSocket.OPEN) {
|
// client.OPEN (instance constant) — NOT WebSocket.OPEN: with
|
||||||
|
// esModuleInterop off, the default `ws` import is undefined at
|
||||||
|
// runtime, so the static crashes. The instance constant is safe.
|
||||||
|
if (client.readyState === client.OPEN) {
|
||||||
client.send(JSON.stringify({
|
client.send(JSON.stringify({
|
||||||
type: 'event',
|
type: 'event',
|
||||||
license_id: payload.license_id,
|
license_id: payload.license_id,
|
||||||
|
|||||||
@@ -108,7 +108,9 @@ export class ConsoleGateway implements OnGatewayConnection, OnGatewayDisconnect
|
|||||||
|
|
||||||
const message = JSON.stringify({ event, data });
|
const message = JSON.stringify({ event, data });
|
||||||
for (const client of clients) {
|
for (const client of clients) {
|
||||||
if (client.readyState === WebSocket.OPEN) {
|
// client.OPEN, not WebSocket.OPEN — esModuleInterop is off so the
|
||||||
|
// default `ws` import is undefined at runtime (would crash on forward).
|
||||||
|
if (client.readyState === client.OPEN) {
|
||||||
client.send(message);
|
client.send(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user