-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
43 lines (33 loc) · 1.1 KB
/
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
36
37
38
39
40
41
42
43
import path from 'path';
import http from 'http';
import express from 'express';
import cors from 'cors';
import { Server } from 'colyseus';
//import { monitor } from '@colyseus/monitor';
//import socialRoutes from '"'@colyseus/social/express'
import { StateHandlerRoom } from './server/abootpal';
const port = Number(process.env.PORT || 25565);
const app = express()
app.use(cors());
app.use(express.json())
const server = http.createServer(app);
const gameServer = new Server({
server,
});
// register your room handlers
gameServer.define('abootpal', StateHandlerRoom);
// register @colyseus/social routes
//app.use("/", socialRoutes);
// register main page
app.use('/', express.static(path.join(__dirname, 'client')));
// register colyseus monitor AFTER registering your room handlers
// this is optional!
const Monitor = require('@colyseus/monitor')
app.use('/colyseus', Monitor.monitor(gameServer));
// shutdown message on server stop
gameServer.onShutdown(function() {
console.log(`Game server is shutting down.`)
})
// listen
gameServer.listen(port);
console.log(`Listening on ws://localhost:${ port }`)