index.js 1.25 KB
Newer Older
Alexander Bazo committed
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,
  ImageViewerRoom = require("./lib/rooms/ImageViewerRoom.js"),
  Logger = require("./lib/utils/Logger.js"),
  ServerConfiguration = require("./lib/config/ServerConfig.js");

Logger.disable();

15 16 17 18
if(process.argv[2] === "debug") {
  Logger.enable();
}

Alexander Bazo committed
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
var app = express(),
  server = http.createServer(app),
  imageServer;

// Logger.enable();

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

imageServer = new colyseus.Server({
  server: server,
  express: app,
});

imageServer.define(ServerConfiguration.getViewerRoomName(), ImageViewerRoom);
// Must be set after game server is created
app.use(ServerConfiguration.getSocialRoute(), socialRoutes);
app.use(ServerConfiguration.getMonitorRoute(), monitor(imageServer));
// Prrobably shoud be set after game server is created
app.use(ServerConfiguration.getViewerRoute(), express.static(ServerConfiguration.getViewerPath(), {
  maxAge: 100,
}));

imageServer.listen(ServerConfiguration.getPort()); 
Logger.log(`Listening on ws://localhost:${ ServerConfiguration.getPort() }`, "Server");