26 lines
670 B
JavaScript
26 lines
670 B
JavaScript
const express = require('express');
|
|
const path = require('path');
|
|
const http = require('http');
|
|
const { Server } = require('socket.io');
|
|
|
|
const app = express();
|
|
const server = http.createServer(app);
|
|
const io = new Server(server);
|
|
|
|
const PORT = process.env.PORT || 3000;
|
|
|
|
// Sert tous les fichiers du dossier "client"
|
|
app.use(express.static(path.join(__dirname, "..", "client")));
|
|
|
|
io.on("connection", (socket) => {
|
|
console.log("Un client s'est connecte : ${socket.id}");
|
|
|
|
socket.on("disconnect", () => {
|
|
console.log("Client deconnecte : ${socket.id}");
|
|
});
|
|
});
|
|
|
|
server.listen(PORT, () => {
|
|
console.log(`Serveur démarré sur http://localhost:${PORT}`);
|
|
});
|