File size: 723 Bytes
1a3fc6f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const app = express();
const http = require("http").Server(app);
const initializeWebSocket = require("./websocket");

// TODO redis store
const io = require("socket.io")(http, {
  cors: {
    origin: "http://localhost:5173",
    methods: ["GET", "POST"],
  },
});

initializeWebSocket(io);

app.use(cors({ credentials: false, origin: "http://localhost:5173" }));

app.use(express.json());

app.use((req, _, next) => {
  req.io = io;
  next();
});


app.get("/", (req, res) => res.send("worked"))

const PORT = process.env.PORT || 3002;
http.listen(PORT, () => {
  console.log(`Server listening at http://localhost:${PORT}`);
});