-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathserver.ts
More file actions
29 lines (23 loc) · 693 Bytes
/
server.ts
File metadata and controls
29 lines (23 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { createServer } from "http";
import cors from "cors";
import express from "express";
import { Server } from "socket.io";
import { SOCKET_RECEIVE_THEME, SOCKET_SEND_THEME } from "./src/constants/socket";
const app = express();
app.use(cors());
const httpServer = createServer(app);
const io = new Server(httpServer, {
cors: {
origin: "http://localhost:3000",
methods: ["GET", "POST"],
},
});
io.on("connection", (socket) => {
socket.on(SOCKET_SEND_THEME, (data) => {
socket.broadcast.emit(SOCKET_RECEIVE_THEME, data);
});
});
const port = process.env.PORT || 3001;
httpServer.listen(port, () => {
console.log(`Express server listening on port ${port}`);
});