added env variables to store hsot and ports

This commit is contained in:
Quentin Roussel
2024-03-27 21:49:10 +01:00
parent 6debf95b8f
commit f70aa52dd0
5 changed files with 25 additions and 5 deletions

View File

@@ -1,11 +1,16 @@
import { createServer } from "http";
import { Server } from "socket.io";
import Game from "./game.js";
import { config } from "dotenv";
//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
//TODO: put this in an environment variable
const ADMIN_PASSWORD = "admin";
//set cors to allow all origins
const io = new Server(httpServer, {
@@ -191,4 +196,6 @@ io.of("player").on("connection", (socket) => {
});
});
httpServer.listen(3000);
httpServer.listen(PORT, HOST, () => {
console.log(`Server running`);
});

View File

@@ -9,6 +9,7 @@
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"dotenv": "^16.4.5",
"socket.io": "^4.7.5"
}
},
@@ -94,6 +95,17 @@
}
}
},
"node_modules/dotenv": {
"version": "16.4.5",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz",
"integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/engine.io": {
"version": "6.5.4",
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.5.4.tgz",

View File

@@ -11,6 +11,7 @@
"license": "ISC",
"type": "module",
"dependencies": {
"dotenv": "^16.4.5",
"socket.io": "^4.7.5"
}
}