attempt to use https

This commit is contained in:
Quentin Roussel
2024-03-27 23:55:53 +01:00
parent c239ab4487
commit c0c21aeeb8
8 changed files with 31 additions and 12 deletions

View File

@@ -1,19 +1,26 @@
import { createServer } from "http";
import { createServer } from "https";
import { Server } from "socket.io";
import Game from "./game.js";
import { config } from "dotenv";
import { readFileSync } from "fs";
//extract admin password from .env file
config();
const ADMIN_PASSWORD = process.env.ADMIN_PASSWORD;
const HOST = process.env.HOST;
const PORT = process.env.PORT;
const httpServer = createServer();
//Password that socket clients will have to send to be able to send admin commands
const httpsServer = createServer({
key: readFileSync(process.env.SSL_KEY, 'utf-8'),
cert: readFileSync(process.env.SSL_CERT, 'utf-8')
});
httpsServer.listen(PORT, HOST, () => {
console.log(`Server running`);
});
//set cors to allow all origins
const io = new Server(httpServer, {
const io = new Server(httpsServer, {
cors: {
origin: "*",
methods: ["GET", "POST"]
@@ -195,7 +202,3 @@ io.of("player").on("connection", (socket) => {
});
});
});
httpServer.listen(PORT, HOST, () => {
console.log(`Server running`);
});