-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
56 lines (45 loc) · 1.67 KB
/
index.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
// Emil hacking because he can't find a babel plugin that does it for some reason
if (!Array.prototype.flatten) {
// eslint-disable-next-line
Array.prototype.flatten = function flatten() {
return this.reduce((acc, cur) => acc.concat(cur), []);
};
}
/* Falcor */
import falcor from 'falcor';
// The custom falcor code we write
import FalcorRouter from 'lib/falcor/FalcorRouter';
/* Helper libraries */
import sourcemap from 'source-map-support';
/* Our helper functions */
import { filterByEnvironment } from 'lib/utilities';
/* The actual server code for the two websites */
import runMainServer from 'server-code/main-server';
import runAdminServer from 'server-code/admin-server';
/* We need to initialize the logger for the whole application */
import { initializeLogger, logger } from 'lib/logger';
initializeLogger(false);
/* Server code starts */
// Announce the build version for clarity
const args = ['DEVELOPMENT BUILD', 'STAGING BUILD', 'PRODUCTION BUILD'];
logger.debug(filterByEnvironment(...args));
// Allow node to use sourcemaps
sourcemap.install();
// Shared serverModel
export const serverModel = new falcor.Model({
source: new FalcorRouter({ maxPaths: 1000 * 1000 }),
// maxSize is 400 MB in production and 80 MB when in development or staging mode
maxSize: filterByEnvironment(400 * 1000 * 1000, 80 * 1000 * 1000),
collectRatio: 0.75,
}).batch();
/**
* Reset cache trending data every minute so we're sure that we always
* have up to date trending data available.
*/
function resetTrending() {
serverModel.invalidate(['trending']);
}
setInterval(resetTrending, 60 * 1000);
// Run the two servers
runMainServer(serverModel);
runAdminServer(serverModel);