DenisSlider2000/backend/index.js
Quentin ANIERE 7ea764730b Fixed https
2022-04-07 19:37:26 +02:00

39 lines
864 B
JavaScript

const fs = require('fs');
const https = require('https');
const express = require('express');
const socketio = require('socket.io');
const app = express();
const https_options = {
key: fs.readFileSync('./privkey.pem'),
cert: fs.readFileSync('./fullchain.pem'),
requestCert: false,
rejectUnauthorized: false
}
const server = https.createServer(https_options, app);
const io = socketio(server, {
cors: {
origin: "https://danby.aniere.fr",
},
secure: true
});
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});
});
server.listen(3000, () => {
console.log("Server started on port 3000");
});