-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathindex.ts
35 lines (24 loc) · 944 Bytes
/
index.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
import * as path from 'path';
import * as express from 'express';
import * as serveIndex from 'serve-index';
import { createServer } from 'http';
import { Server } from 'colyseus';
import { monitor } from '@colyseus/monitor';
// Import demo room handlers
import { IOGLockStepSyncRoom } from "./rooms/IOGLockStepSyncRoom";
const port = Number(process.env.PORT || 2567);
const app = express();
// Attach WebSocket Server on HTTP Server.
const gameServer = new Server({
server: createServer(app)
});
gameServer.register("room",IOGLockStepSyncRoom);
app.use('/', express.static(path.join(__dirname, "static")));
app.use('/', serveIndex(path.join(__dirname, "static"), {'icons': true}))
// (optional) attach web monitoring panel
app.use('/colyseus', monitor(gameServer));
gameServer.onShutdown(function(){
console.log(`game server is going down.`);
});
gameServer.listen(port);
console.log(`Listening on http://localhost:${ port }`);