mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
* start upgrade to node 8 * upgrade travis * improve travis * Remove bluebird, babel (except for modules) from server (WIP) (#9947) * remove bluebird, babel from server (except for modules) * fixes * fix path * fix path * fix export * fix export * fix test * fix tests * remove plugin for transform-object-rest-spread since it is supported in node8 * babel: correct syntax rest spread * remove bluebird * update migrations archive readme * fix package-lock.json * fix typo * add package-loc
46 lines
1.4 KiB
JavaScript
46 lines
1.4 KiB
JavaScript
'use strict';
|
|
/* eslint-disable global-require, no-process-env */
|
|
|
|
// Register babel hook so we can write the real entry file (server.js) in ES6
|
|
// In production, the es6 code is pre-transpiled so it doesn't need it
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
require('babel-register');
|
|
}
|
|
|
|
// Initialize configuration BEFORE anything
|
|
const setupNconf = require('./libs/setupNconf');
|
|
setupNconf();
|
|
|
|
const nconf = require('nconf');
|
|
const stackimpact = require('stackimpact');
|
|
|
|
const cluster = require('cluster');
|
|
const logger = require('./libs/logger');
|
|
|
|
const IS_PROD = nconf.get('IS_PROD');
|
|
const IS_DEV = nconf.get('IS_DEV');
|
|
const CORES = Number(nconf.get('WEB_CONCURRENCY')) || 0;
|
|
|
|
if (IS_PROD) {
|
|
stackimpact.start({
|
|
agentKey: nconf.get('STACK_IMPACT_KEY'),
|
|
appName: 'Habitica',
|
|
});
|
|
}
|
|
|
|
// Setup the cluster module
|
|
if (CORES !== 0 && cluster.isMaster && (IS_DEV || IS_PROD)) {
|
|
// Fork workers. If config.json has WEB_CONCURRENCY=x, use that - otherwise, use all cpus-1 (production)
|
|
for (let i = 0; i < CORES; i += 1) {
|
|
cluster.fork();
|
|
}
|
|
|
|
cluster.on('disconnect', function onWorkerDisconnect (worker) {
|
|
let w = cluster.fork(); // replace the dead worker
|
|
|
|
logger.info('[%s] [master:%s] worker:%s disconnect! new worker:%s fork', new Date(), process.pid, worker.process.pid, w.process.pid);
|
|
});
|
|
} else {
|
|
module.exports = require('./server.js');
|
|
}
|