2016-05-05 02:29:43 +08:00
|
|
|
import { logger } from '/imports/startup/server/logger';
|
2016-05-05 04:25:34 +08:00
|
|
|
import '/server/server';
|
|
|
|
import { RedisPubSub } from '/imports/startup/server/RedisPubSub';
|
2016-05-05 02:29:43 +08:00
|
|
|
import { EventQueue } from '/imports/startup/server/EventQueue';
|
2016-06-02 01:18:13 +08:00
|
|
|
import { clearCollections } from '/imports/api/common/server/helpers';
|
2016-10-08 00:36:27 +08:00
|
|
|
import Locales from '/imports/locales';
|
2016-05-05 02:29:43 +08:00
|
|
|
|
2016-05-05 05:49:01 +08:00
|
|
|
Meteor.startup(function () {
|
2016-08-17 23:48:03 +08:00
|
|
|
redisPubSub = new RedisPubSub();
|
|
|
|
|
2016-05-05 04:25:34 +08:00
|
|
|
clearCollections();
|
2016-08-17 23:48:03 +08:00
|
|
|
const APP_CONFIG = Meteor.settings.public.app;
|
|
|
|
|
2016-08-20 05:08:46 +08:00
|
|
|
let determineConnectionType = function () {
|
2016-07-28 00:36:33 +08:00
|
|
|
let baseConnection = 'HTTP';
|
2016-08-20 05:08:46 +08:00
|
|
|
if (APP_CONFIG.httpsConnection) {
|
2016-07-28 00:36:33 +08:00
|
|
|
baseConnection += ('S');
|
|
|
|
}
|
2016-08-20 05:08:46 +08:00
|
|
|
|
2016-07-28 00:36:33 +08:00
|
|
|
return baseConnection;
|
|
|
|
};
|
2016-08-20 05:08:46 +08:00
|
|
|
|
2016-07-28 00:36:33 +08:00
|
|
|
logger.info(`server start. Connection type:${determineConnectionType()}`);
|
2016-08-25 07:13:42 +08:00
|
|
|
logger.info('APP_CONFIG=');
|
|
|
|
logger.info(APP_CONFIG);
|
|
|
|
logger.info('Running in environment type:' + Meteor.settings.runtime.env);
|
2016-05-05 04:25:34 +08:00
|
|
|
});
|
2016-05-05 01:00:57 +08:00
|
|
|
|
2016-06-14 01:56:41 +08:00
|
|
|
WebApp.connectHandlers.use('/check', (req, res, next) => {
|
|
|
|
let payload = { html5clientStatus: 'running' };
|
|
|
|
|
|
|
|
res.setHeader('Content-Type', 'application/json');
|
|
|
|
res.writeHead(200);
|
|
|
|
res.end(JSON.stringify(payload));
|
|
|
|
});
|
|
|
|
|
2016-10-08 00:36:27 +08:00
|
|
|
WebApp.connectHandlers.use('/locale', (req, res) => {
|
2016-10-13 01:03:10 +08:00
|
|
|
|
2016-10-08 00:36:27 +08:00
|
|
|
let defaultLocale = 'en';
|
2016-10-13 01:03:10 +08:00
|
|
|
let [locale, region] = req.query.locale.split('-');
|
2016-10-08 00:36:27 +08:00
|
|
|
|
2016-10-13 01:03:10 +08:00
|
|
|
const defaultMessages = Locales[defaultLocale];
|
2016-10-08 00:36:27 +08:00
|
|
|
|
2016-10-13 01:03:10 +08:00
|
|
|
let messages = Object.assign(
|
|
|
|
{},
|
|
|
|
defaultMessages,
|
|
|
|
Locales[locale],
|
|
|
|
Locales[`${locale}-${region}`],
|
|
|
|
);
|
2016-10-08 00:36:27 +08:00
|
|
|
|
|
|
|
res.setHeader('Content-Type', 'application/json');
|
|
|
|
res.writeHead(200);
|
2016-10-13 01:03:10 +08:00
|
|
|
res.end(JSON.stringify(messages));
|
|
|
|
|
2016-10-08 00:36:27 +08:00
|
|
|
});
|
|
|
|
|
2016-05-05 01:00:57 +08:00
|
|
|
export const myQueue = new EventQueue();
|
|
|
|
|
|
|
|
export const eventEmitter = new (Npm.require('events').EventEmitter);
|
|
|
|
|
2016-08-17 23:48:03 +08:00
|
|
|
export let redisPubSub = {};
|