index.js 1.06 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/* eslint-env node */

const http = require("http"),
  express = require("express"),
  cors = require("cors"),
  colyseus = require("colyseus"),
  monitor = require("@colyseus/monitor").monitor,
  socialRoutes = require("@colyseus/social/express").default,
  StarGazerRoom = require("./lib/rooms/StarGazerRoom.js"),
  Logger = require("./lib/utils/Logger.js"),
  Config = require("./lib/config/ServerConfig.js");

var app = express(),
  server = http.createServer(app),
  gameServer;

17
// Logger.enable();
Alexander Bazo committed
18 19 20 21

app.use(cors());
app.use(express.json());

22
gameServer = new colyseus.Server({
Alexander Bazo committed
23
  server: server,
Alexander Bazo committed
24
  express: app
Alexander Bazo committed
25 26
});

27 28 29 30 31
gameServer.define(Config.getGameRoomName(), StarGazerRoom);
// Must be set after game server is created
app.use(Config.getSocialRoute(), socialRoutes);
app.use(Config.getMonitorRoute(), monitor(gameServer));
// Prrobably shoud be set after game server is created
32 33 34
app.use(Config.getGameRoute(), express.static(Config.getGamePath(), {
  maxAge: 100
}));
Alexander Bazo committed
35

36 37
gameServer.listen(Config.getPort()); 
Logger.log(`Listening on ws://localhost:${ Config.getPort() }`, "Server");