-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.ts
39 lines (36 loc) · 979 Bytes
/
server.ts
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
35
36
37
38
39
import express from "express";
import { Server as SocketIoServer } from "socket.io";
import { createServer } from "http";
import { initIo } from "./setup";
import { initExpress } from "./setup/httpServer";
import { instrument } from "@socket.io/admin-ui";
const app = express();
const httpServer = createServer(app);
const io = new SocketIoServer(httpServer, {
cors: {
origin: [
"http://localhost:3000",
"http://localhost:5500",
"http://localhost:5173",
"http://127.0.0.1:5500",
"https://admin.socket.io",
"http://localhost",
"http://localhost:8000",
"http://localhost:8080",
"http://127.0.0.1:8080",
],
credentials: true,
},
});
// 初始化 socket.io 配置
instrument(io, {
auth: false,
mode: "development",
});
initIo(io);
// 初始化 express 配置
initExpress(app);
let PORT = process.env.PORT || 3000;
httpServer.listen(PORT, () => {
console.log("listening on http://localhost:" + PORT);
});