index.js 1.04 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* 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;

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 32
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
app.use(Config.getGameRoute(), express.static(Config.getGamePath()));
Alexander Bazo committed
33

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