Skip to content

Commit 3aab752

Browse files
committed
Give extras endpoint TLS
1 parent f96c645 commit 3aab752

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/index.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import { WebsocketIncoming } from "./connector/websocketIncoming";
55
import { MatchController } from "./controller/MatchController";
66
import logging from "./util/Logging";
77
import { PreviewHandler } from "./util/previews/PreviewHandler";
8+
import { readFileSync } from "fs";
9+
import { createServer as createSecureServer } from "https";
810
const Log = logging("Status");
11+
require("dotenv").config();
912

1013
const websocketIncoming = new WebsocketIncoming();
1114
const previewHandler = PreviewHandler.getInstance(websocketIncoming);
@@ -36,6 +39,16 @@ app.get("/preview/:previewCode", async (req: Request, res: Response) => {
3639
res.status(200).json(previewMatch);
3740
});
3841

39-
app.listen(port, () => {
40-
Log.info(`Extras available on port ${port}`);
41-
});
42+
if (process.env.INSECURE == "true") {
43+
app.listen(port, () => {
44+
Log.info(`Extras available on port ${port}`);
45+
});
46+
} else {
47+
const key = readFileSync(process.env.SERVER_KEY!);
48+
const cert = readFileSync(process.env.SERVER_CERT!);
49+
const creds = { key, cert };
50+
const server = createSecureServer(creds, app);
51+
server.listen(port, () => {
52+
Log.info(`Extras available on port ${port} (TLS)`);
53+
});
54+
}

0 commit comments

Comments
 (0)