diff --git a/index.ts b/index.ts index cabceb5..6a995e6 100755 --- a/index.ts +++ b/index.ts @@ -7,7 +7,12 @@ import { processMessage, trackConnection, } from "./websocket-handler"; -import { getVersionNumber, writeStatNumber, writeStatString, writeSuccess } from "./utility"; +import { + getVersionNumber, + writeStatNumber, + writeStatString, + writeSuccess, +} from "./utility"; import Colors from "colors"; import IP from "ip"; @@ -61,6 +66,23 @@ async function main() { forgetConnection(ws); }, }, + + tls: await (async () => { + const keyFile = Bun.file("./key.pem"); + const certFile = Bun.file("./cert.pem"); + + if ( + (await keyFile.exists()) == false || + (await certFile.exists()) == false + ) + return undefined; + + return { + key: keyFile, + cert: certFile, + passphrase: process.env.TLS_PASSPHRASE, + }; + })(), }); function createFileResponse(requestPath: string): Response { @@ -76,7 +98,7 @@ async function main() { return [ ["server url", server.url.toString()], ["server ip address", IP.address()], - ["server version", versionNumber] + ["server version", versionNumber], ]; } diff --git a/static/dist/index.js b/static/dist/index.js index 670aa91..d2ef06c 100644 --- a/static/dist/index.js +++ b/static/dist/index.js @@ -339,7 +339,7 @@ setTimeout(connect, 2e3); }; function connect() { - UDN.connect(`ws://${window.location.host}`); + UDN.connect(`wss://${window.location.host}`); } connect(); var isDisconnected = new State(true); diff --git a/static/src/model.tsx b/static/src/model.tsx index 4259e42..f335672 100644 --- a/static/src/model.tsx +++ b/static/src/model.tsx @@ -33,7 +33,7 @@ UDN.ondisconnect = () => { }; function connect() { - UDN.connect(`ws://${window.location.host}`); + UDN.connect(`wss://${window.location.host}`); } connect();