History

start phase 1

Julius Marminge committed 8 months ago

Commit fefea0b1 parent 6954d1b16 files · +625 −4904Browse files

Showing the changes to apps/server/src/wsServer.ts (1 of 16 files). Show all

Unified · Split

apps/server/src/wsServer.ts+3−2
@@ -72,7 +72,7 @@ const isServerNotRunningError = (error: unknown): boolean => { · 71 unmodified lines
72};72};
73 73
74function rejectUpgrade(socket: Duplex, statusCode: number, message: string): void {74function rejectUpgrade(socket: Duplex, statusCode: number, message: string): void {
75 socket.write(75 socket.end(
76 `HTTP/1.1 ${statusCode} ${statusCode === 401 ? "Unauthorized" : "Bad Request"}\r\n` +76 `HTTP/1.1 ${statusCode} ${statusCode === 401 ? "Unauthorized" : "Bad Request"}\r\n` +
77 "Connection: close\r\n" +77 "Connection: close\r\n" +
78 "Content-Type: text/plain\r\n" +78 "Content-Type: text/plain\r\n" +
@@ -80,7 +80,6 @@ function rejectUpgrade(socket: Duplex, statusCode: number, message: string): voi · 1 unmodified line
80 "\r\n" +80 "\r\n" +
81 message,81 message,
82 );82 );
83 socket.destroy();
84}83}
85 84
86function parseBooleanEnv(value: string | undefined): boolean | undefined {85function parseBooleanEnv(value: string | undefined): boolean | undefined {
@@ -506,6 +505,8 @@ export const createServer = Effect.fn(function* (options: ServerOptions = {}): E · 419 unmodified lines
506 });505 });
507 506
508 httpServer.on("upgrade", (request, socket, head) => {507 httpServer.on("upgrade", (request, socket, head) => {
508 socket.on("error", () => {}); // Prevent unhandled `EPIPE`/`ECONNRESET` from crashing the process if the client disconnects mid-handshake
509
509 if (authToken) {510 if (authToken) {
510 let providedToken: string | null = null;511 let providedToken: string | null = null;
511 try {512 try {