chore: make ws self test work under bun
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Build / build (pull_request) Successful in 1m12s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Build / build (pull_request) Successful in 1m12s
				
			This commit is contained in:
		
							parent
							
								
									636d3100f3
								
							
						
					
					
						commit
						bac7104db6
					
				@ -10,7 +10,7 @@ import { Account } from "../models/loginModel";
 | 
				
			|||||||
import { createAccount, createNonce, getUsernameFromEmail, isCorrectPassword } from "./loginService";
 | 
					import { createAccount, createNonce, getUsernameFromEmail, isCorrectPassword } from "./loginService";
 | 
				
			||||||
import { IDatabaseAccountJson } from "../types/loginTypes";
 | 
					import { IDatabaseAccountJson } from "../types/loginTypes";
 | 
				
			||||||
import { HydratedDocument } from "mongoose";
 | 
					import { HydratedDocument } from "mongoose";
 | 
				
			||||||
import { Agent, WebSocket } from "undici";
 | 
					import { Agent, WebSocket as UnidiciWebSocket } from "undici";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let httpServer: http.Server | undefined;
 | 
					let httpServer: http.Server | undefined;
 | 
				
			||||||
let httpsServer: https.Server | undefined;
 | 
					let httpsServer: https.Server | undefined;
 | 
				
			||||||
@ -46,13 +46,9 @@ export const startWebServer = (): void => {
 | 
				
			|||||||
                "Access the WebUI in your browser at http://localhost" + (httpPort == 80 ? "" : ":" + httpPort)
 | 
					                "Access the WebUI in your browser at http://localhost" + (httpPort == 80 ? "" : ":" + httpPort)
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // https://github.com/oven-sh/bun/issues/20547
 | 
					 | 
				
			||||||
            if (!process.versions.bun) {
 | 
					 | 
				
			||||||
            void runWsSelfTest("wss", httpsPort).then(ok => {
 | 
					            void runWsSelfTest("wss", httpsPort).then(ok => {
 | 
				
			||||||
                if (!ok) {
 | 
					                if (!ok) {
 | 
				
			||||||
                        logger.warn(
 | 
					                    logger.warn(`WSS self-test failed. The server may not actually be reachable at port ${httpsPort}.`);
 | 
				
			||||||
                            `WSS self-test failed. The server may not actually be reachable at port ${httpsPort}.`
 | 
					 | 
				
			||||||
                        );
 | 
					 | 
				
			||||||
                    if (process.platform == "win32") {
 | 
					                    if (process.platform == "win32") {
 | 
				
			||||||
                        logger.warn(
 | 
					                        logger.warn(
 | 
				
			||||||
                            `You can check who actually has that port via powershell: Get-Process -Id (Get-NetTCPConnection -LocalPort ${httpsPort}).OwningProcess`
 | 
					                            `You can check who actually has that port via powershell: Get-Process -Id (Get-NetTCPConnection -LocalPort ${httpsPort}).OwningProcess`
 | 
				
			||||||
@ -60,21 +56,35 @@ export const startWebServer = (): void => {
 | 
				
			|||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const runWsSelfTest = (protocol: "ws" | "wss", port: number): Promise<boolean> => {
 | 
					const runWsSelfTest = (protocol: "ws" | "wss", port: number): Promise<boolean> => {
 | 
				
			||||||
    return new Promise(resolve => {
 | 
					    return new Promise(resolve => {
 | 
				
			||||||
        const agent = new Agent({ connect: { rejectUnauthorized: false } });
 | 
					        // https://github.com/oven-sh/bun/issues/20547
 | 
				
			||||||
        const client = new WebSocket(`${protocol}://localhost:${port}/custom/selftest`, { dispatcher: agent });
 | 
					        if (process.versions.bun) {
 | 
				
			||||||
 | 
					            const client = new WebSocket(`${protocol}://localhost:${port}/custom/selftest`, {
 | 
				
			||||||
 | 
					                tls: { rejectUnauthorized: false }
 | 
				
			||||||
 | 
					            } as unknown as string);
 | 
				
			||||||
            client.onmessage = (e): void => {
 | 
					            client.onmessage = (e): void => {
 | 
				
			||||||
                resolve(e.data == "SpaceNinjaServer");
 | 
					                resolve(e.data == "SpaceNinjaServer");
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
            client.onerror = client.onclose = (): void => {
 | 
					            client.onerror = client.onclose = (): void => {
 | 
				
			||||||
                resolve(false);
 | 
					                resolve(false);
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            const agent = new Agent({ connect: { rejectUnauthorized: false } });
 | 
				
			||||||
 | 
					            const client = new UnidiciWebSocket(`${protocol}://localhost:${port}/custom/selftest`, {
 | 
				
			||||||
 | 
					                dispatcher: agent
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            client.onmessage = (e): void => {
 | 
				
			||||||
 | 
					                resolve(e.data == "SpaceNinjaServer");
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					            client.onerror = client.onclose = (): void => {
 | 
				
			||||||
 | 
					                resolve(false);
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user