vybe/index.js

39 lines
761 B
JavaScript
Raw Normal View History

2023-05-05 19:33:05 -07:00
const express = require("express");
const http = require("http");
const { Server } = require("socket.io");
2023-05-29 18:08:20 -07:00
const compression = require("compression");
2023-05-08 21:40:16 -07:00
const app = express();
2023-05-29 18:08:20 -07:00
app.use(compression());
2023-05-08 21:40:16 -07:00
const server = http.createServer(app);
2023-05-05 19:33:05 -07:00
const io = new Server(server, {
cors: {
2023-05-29 18:08:20 -07:00
origin: true,
2023-05-05 19:33:05 -07:00
},
});
const PORT = process.env.PORT || 3435;
const actions = require("./src/actions");
2023-05-28 14:56:08 -07:00
io.cache = {};
2023-05-05 19:33:05 -07:00
io.on("connection", (socket) => {
for (let action in actions) {
socket.on(action, (msg) =>
2023-05-28 14:56:08 -07:00
actions[action](
msg,
(response) => socket.emit(action, response),
socket,
io
)
2023-05-05 19:33:05 -07:00
);
}
});
server.listen(PORT, () => {
console.log("server running on port " + PORT);
});
2023-05-06 20:55:04 -07:00
2023-05-07 18:43:57 -07:00
app.use(express.static("client"));