-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.js
107 lines (87 loc) · 2.44 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
const ss = require("socketstream");
const { generate } = require("shortid");
const { Server } = require("http");
const { SS_PACK, REDIS, PORT, NODE_PORT, NODE_IP } = process.env;
module.exports = (id) => {
if (ss.env === "production") {
const opts = SS_PACK
? { all: true, keepOldFiles: true, id: generate() }
: {};
ss.client.packAssets(opts);
}
if (REDIS) {
const redisConf = {
host: REDIS,
};
ss.session.store.use("redis", redisConf);
ss.publish.transport.use("redis", redisConf);
} else {
ss.session.store.use("redis");
ss.publish.transport.use("redis");
}
ss.client.define("ui", {
view: "ui.html",
css: ["*"],
code: [
"libs/polymaps.js",
"libs/spin.js",
"libs/jquery.linkify-1.0-min.js",
"libs/jquery.fastLiveFilter.js",
"libs/paper.js",
"libs/mordernizr.js",
"libs/modernizr-pointerevents.min.js",
"libs/uuid.js",
"libs/history.js",
"libs/nprogress.js",
"libs/date.js",
"libs/fly.js",
"libs/sha512.js",
"libs/fetch.js",
"libs/encoding.js",
"libs/chunked-request.js",
"libs/events.js",
"libs/superagent.js",
"libs/throttle.js",
"libs/indexeddbshim-UnicodeIdentifiers.js",
"libs/dexie.js",
"libs/classList.js",
"libs/custom-event-polyfill.js",
"libs/quickconnect.js",
"app",
],
tmpl: "*",
});
ss.client.set({ liveReload: true });
ss.http.route("/health", (req, res) => {
res.writeHead(200);
res.end();
});
ss.http.middleware.prepend("/robots.txt", (req, res) => {
res.end(
`User-agent: Twitterbot
Disallow:`
);
});
ss.http.middleware.append("/_wes", require("./server/whiteboardEventStore"));
ss.http.middleware.append("/_screen", require("./screen"));
ss.http.middleware.append("/", require("./social"));
ss.http.middleware.append(require("./server/middleware/rate").limit());
ss.http.route("/", (req, res) => {
res.serveClient("ui");
});
if (SS_PACK) {
setImmediate(() => {
process.exit(0);
});
}
// Start web server
const server = Server(ss.http.middleware);
const port = PORT || (NODE_PORT || 3000) + id * 10;
// TCP/IP socket IO
server.listen(port, NODE_IP || "0.0.0.0");
// Start SocketStream
ss.start(server);
const rtcServer = Server();
rtcServer.listen(port + 100, NODE_IP || "0.0.0.0");
require("./rtc")({ server: rtcServer, path: "/_rtc/" });
};