diff --git a/src/config.ts b/src/config.ts index 396f8a3..ae8e9b5 100644 --- a/src/config.ts +++ b/src/config.ts @@ -14,6 +14,13 @@ export const config = convict({ default: false, arg: "allowDeletingFiles", }, + host: { + doc: "The host to bind to.", + format: "String", + nullable: true, + default: null, + arg: "host", + }, port: { doc: "The port to bind to.", format: "Number", diff --git a/src/index.ts b/src/index.ts index 196b988..f2a1063 100644 --- a/src/index.ts +++ b/src/index.ts @@ -56,7 +56,8 @@ export async function start() { signal.emit(EventType.MessageSend, fileRemovalEventToMsg(fileEvent)), ); - console.log(`Server is ready, running on ${config.get("port")}!`); + const configHost = config.get("host"); + console.log(`Server is ready, running on ${configHost != null ? configHost + ":" : ""}${config.get("port")}!`); process.on("SIGINT", function () { console.log("Shutting down!"); diff --git a/src/networking/webSocket.ts b/src/networking/webSocket.ts index 78faca7..ab78273 100644 --- a/src/networking/webSocket.ts +++ b/src/networking/webSocket.ts @@ -6,7 +6,8 @@ import { Message } from "../interfaces.js"; import { messageTracker } from "./messageTracker.js"; export function setupSocket(signaller: Signal) { - const wss = new WebSocketServer({ port: config.get("port") }); + const configHost: string | null = config.get("host"); + const wss = new WebSocketServer({ port: config.get("port"), host: configHost ?? undefined }); wss.on("connection", function connection(ws) { function sendMessage(msg: Message) {