latterworks commited on
Commit
7c76abf
·
verified ·
1 Parent(s): 03981fe

Create src/index.ts

Browse files
Files changed (1) hide show
  1. src/index.ts +34 -0
src/index.ts ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // src/index.ts
2
+ import http from "http";
3
+ import express from "express";
4
+ import cors from "cors";
5
+ import { Server } from "@colyseus/core";
6
+ import { WebSocketTransport } from "@colyseus/ws-transport";
7
+ import { MyRoom } from "./rooms/MyRoom";
8
+
9
+ const app = express();
10
+ app.use(cors());
11
+ app.use(express.json());
12
+
13
+ const server = http.createServer(app);
14
+
15
+ const gameServer = new Server({
16
+ transport: new WebSocketTransport({ server }),
17
+ });
18
+
19
+ gameServer.define("my_room", MyRoom);
20
+
21
+ const PORT = Number(process.env.PORT) || 2567; // Default to 2567 for local, 7860 on HF Spaces
22
+
23
+ gameServer.listen(PORT)
24
+ .then(() => {
25
+ console.log(`Colyseus server listening on ws://localhost:${PORT}`);
26
+ console.log("Room 'my_room' is ready for connections.");
27
+ })
28
+ .catch((err) => {
29
+ console.error("Error starting Colyseus server:", err);
30
+ });
31
+
32
+ app.get("/", (req, res) => {
33
+ res.send("Colyseus game server is running!");
34
+ });