index.js 1.09 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* 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),
15
  pathToClient = process.argv[2],
16 17
  gameServer;

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

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

23
gameServer = new colyseus.Server({
Alexander Bazo committed
24
  server: server,
Alexander Bazo committed
25
  express: app
Alexander Bazo committed
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
33
app.use(Config.getGameRoute(), express.static(pathToClient, {
34 35
  maxAge: 100
}));
Alexander Bazo committed
36

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