const express = require("express"); const http = require("http"); const { Server } = require("socket.io"); const compression = require("compression"); const app = express(); app.use(compression()); const server = http.createServer(app); const io = new Server(server, { cors: { origin: true, }, }); const PORT = process.env.PORT || 3435; const actions = require("./src/actions"); io.cache = {}; io.on("connection", (socket) => { for (let action in actions) { socket.on(action, (msg) => actions[action]( msg, (response) => socket.emit(action, response), socket, io ) ); } }); server.listen(PORT, () => { console.log("server running on port " + PORT); }); app.use(express.static("client"));