@@ -5,7 +5,10 @@ import { WebsocketIncoming } from "./connector/websocketIncoming";
55import { MatchController } from "./controller/MatchController" ;
66import logging from "./util/Logging" ;
77import { PreviewHandler } from "./util/previews/PreviewHandler" ;
8+ import { readFileSync } from "fs" ;
9+ import { createServer as createSecureServer } from "https" ;
810const Log = logging ( "Status" ) ;
11+ require ( "dotenv" ) . config ( ) ;
912
1013const websocketIncoming = new WebsocketIncoming ( ) ;
1114const 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