-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
38 lines (30 loc) · 891 Bytes
/
server.js
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
//@flow
import http from "http";
import express from "express";
import websocket from "./websocket";
// Remove console log in production mode
if(process.env.NODE_ENV == "production") {
// $FlowFixMe
console.log = () => {};
}
// $FlowFixMe
if (typeof(PhusionPassenger) != 'undefined') {
PhusionPassenger.configure({ autoInstall: false });
}
const app = express();
app.use(express.static("public"));
/**
* server listen on 4000 needed for WebSockets to run on that port.
* This port is then used by client to communicate over WebSocket.
*/
const server: Object = http.createServer(app);
if (typeof(PhusionPassenger) != 'undefined') {
server.listen('passenger');
} else {
server.listen(process.env.PORT || 4000, () => {});
}
const WebSocketServer = require("websocket").server;
const wsServer = new WebSocketServer({
httpServer: server
});
websocket.init(wsServer);