-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
20 lines (16 loc) · 739 Bytes
/
server.ts
File metadata and controls
20 lines (16 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { createServer, type RequestListener, type IncomingMessage, type ServerResponse } from "http";
import { WebSocketServer } from "ws";
import { handler } from "./build/handler.js";
import GameServer from "./src/server/GameServer";
const port = process.env.PORT || 3000;
const server = createServer(<RequestListener<typeof IncomingMessage, typeof ServerResponse>>handler);
const wss = new WebSocketServer({ noServer: true });
const gameServer = new GameServer(wss);
server.on("upgrade", (request, socket, head) => {
wss.handleUpgrade(request, socket, head, (ws) => {
wss.emit("connection", ws, request);
})
})
server.listen(port, () => {
console.log(`Server is listening on port ${port}`);
})