forked from OpenWF/SpaceNinjaServer
chore: make ws self test work under bun (#2268)
Reviewed-on: OpenWF/SpaceNinjaServer#2268 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
parent
9a034b1c8a
commit
f242d9f873
@ -10,7 +10,7 @@ import { Account } from "../models/loginModel";
|
||||
import { createAccount, createNonce, getUsernameFromEmail, isCorrectPassword } from "./loginService";
|
||||
import { IDatabaseAccountJson } from "../types/loginTypes";
|
||||
import { HydratedDocument } from "mongoose";
|
||||
import { Agent, WebSocket } from "undici";
|
||||
import { Agent, WebSocket as UnidiciWebSocket } from "undici";
|
||||
|
||||
let httpServer: http.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)
|
||||
);
|
||||
|
||||
// https://github.com/oven-sh/bun/issues/20547
|
||||
if (!process.versions.bun) {
|
||||
void runWsSelfTest("wss", httpsPort).then(ok => {
|
||||
if (!ok) {
|
||||
logger.warn(
|
||||
`WSS self-test failed. The server may not actually be reachable at port ${httpsPort}.`
|
||||
);
|
||||
logger.warn(`WSS self-test failed. The server may not actually be reachable at port ${httpsPort}.`);
|
||||
if (process.platform == "win32") {
|
||||
logger.warn(
|
||||
`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> => {
|
||||
return new Promise(resolve => {
|
||||
const agent = new Agent({ connect: { rejectUnauthorized: false } });
|
||||
const client = new WebSocket(`${protocol}://localhost:${port}/custom/selftest`, { dispatcher: agent });
|
||||
// https://github.com/oven-sh/bun/issues/20547
|
||||
if (process.versions.bun) {
|
||||
const client = new WebSocket(`${protocol}://localhost:${port}/custom/selftest`, {
|
||||
tls: { rejectUnauthorized: false }
|
||||
} as unknown as string);
|
||||
client.onmessage = (e): void => {
|
||||
resolve(e.data == "SpaceNinjaServer");
|
||||
};
|
||||
client.onerror = client.onclose = (): void => {
|
||||
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