Change HTTP server to require a function call to initialize

This commit is contained in:
Hri7566 2024-09-20 11:13:27 -04:00
parent 617c8c4bc5
commit a82839085f
3 changed files with 92 additions and 87 deletions

2
public

@ -1 +1 @@
Subproject commit a8a0182686cec166c3042697c639c5ca8b6acf6b Subproject commit 1dc00c7f885ac919a1bda7d4c749d33bd594c42f

View File

@ -13,14 +13,13 @@
// There are a lot of unhinged bs comments in this repo // There are a lot of unhinged bs comments in this repo
// Pay no attention to the ones that cuss you out // Pay no attention to the ones that cuss you out
// If you don't load the server first, bun will literally segfault
import "./ws/server";
import { loadForcedStartupChannels } from "./channel/forceload"; import { loadForcedStartupChannels } from "./channel/forceload";
import { Logger } from "./util/Logger"; import { Logger } from "./util/Logger";
// docker hates this next one // docker hates this next one
import { startReadline } from "./util/readline"; import { startReadline } from "./util/readline";
import { loadDefaultPermissions } from "./data/permissions"; import { loadDefaultPermissions } from "./data/permissions";
import { loadBehaviors } from "./event/behaviors"; import { loadBehaviors } from "./event/behaviors";
import { startHTTPServer } from "./ws/server";
// wrapper for some reason // wrapper for some reason
export function startServer() { export function startServer() {
@ -38,6 +37,8 @@ export function startServer() {
// Break the console // Break the console
logger.info("Starting REPL"); logger.info("Starting REPL");
startReadline(); startReadline();
startHTTPServer();
logger.info("Ready"); logger.info("Ready");
} }

View File

@ -7,7 +7,7 @@ import { Socket, socketsByUUID } from "./Socket";
import env from "../util/env"; import env from "../util/env";
import { getMOTD } from "../util/motd"; import { getMOTD } from "../util/motd";
import nunjucks from "nunjucks"; import nunjucks from "nunjucks";
import type { ServerWebSocket } from "bun"; import type { Server, ServerWebSocket } from "bun";
import { ConfigManager } from "~/util/config"; import { ConfigManager } from "~/util/config";
import { config as usersConfig } from "./usersConfig"; import { config as usersConfig } from "./usersConfig";
@ -59,7 +59,10 @@ async function getIndex() {
type ServerWebSocketMPP = ServerWebSocket<{ ip: string; socket: Socket }>; type ServerWebSocketMPP = ServerWebSocket<{ ip: string; socket: Socket }>;
export const app = Bun.serve<{ ip: string }>({ export let app: Server;
export function startHTTPServer() {
app = Bun.serve<{ ip: string }>({
port: env.PORT, port: env.PORT,
hostname: "0.0.0.0", hostname: "0.0.0.0",
fetch: (req, server) => { fetch: (req, server) => {
@ -170,6 +173,7 @@ export const app = Bun.serve<{ ip: string }>({
} }
} }
} }
}); });
logger.info("Listening on port", env.PORT); logger.info("Listening on port", env.PORT);
}