DenisSlider2000/index.js

52 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-04-09 00:32:32 +02:00
const fs = require("fs");
const https = require("https");
const express = require("express");
const socketio = require("socket.io");
2022-04-07 19:09:47 +02:00
const app = express();
2022-04-07 19:37:26 +02:00
const https_options = {
2022-04-09 00:32:32 +02:00
key: fs.readFileSync("./privkey.pem"),
cert: fs.readFileSync("./fullchain.pem"),
2022-04-07 19:37:26 +02:00
requestCert: false,
rejectUnauthorized: false
}
2022-04-11 12:34:40 +02:00
const socketHTTPSServer = https.createServer(https_options, app);
const webHTTPSServer = https.createServer(https_options, app);
2022-04-07 19:37:26 +02:00
2022-04-11 12:34:40 +02:00
const io = socketio(socketHTTPSServer, {
2022-04-07 19:37:26 +02:00
cors: {
origin: "https://danby.aniere.fr",
},
secure: true
});
2022-04-07 19:09:47 +02:00
usersConnected = 0
io.on("connection", (client) => {
usersConnected++;
client.on("disconnect", () => {
usersConnected--;
io.sockets.emit("update-count", {value: usersConnected});
});
io.sockets.emit("update-count", {value: usersConnected});
});
2022-04-11 12:34:40 +02:00
app.use(express.static("src"));
app.listen(80, () => {
console.log("Web server started on port 80")
});
webHTTPSServer.listen(443, () => {
console.log("Web HTTPS server started on port 443");
});
socketHTTPSServer.listen(3000, () => {
console.log("Socket HTTPS server started on port 3000");
2022-04-07 19:09:47 +02:00
});