Files
habitica/website/server/middlewares/api-v3/locals.js
Matteo Pagliazzi 0880850408 Real-time Chat (#7664)
* feat(realtime-chat): add Pusher library to the server

* feat(realtime-chat): only for private groups

* feat(realtime-chat): add authentication endpoint for Pusher

* feat(realtime-chat): client proof of concept

* fix typo in apidoc

* feat(realtime-chat): redo authentication and write integration tests

* remove firebase code

* fix client side tests

* fix line ending in bower.json

* feat(realtime chat): use presence channels for parties, send events & disconnect clients if user leaves or is removed from party, automatically update UI

* pusher: enable all events in the background

* fix pusher integration tests
2016-07-02 15:17:24 +02:00

64 lines
2.2 KiB
JavaScript

import nconf from 'nconf';
import _ from 'lodash';
import shared from '../../../../common';
import * as i18n from '../../libs/api-v3/i18n';
import {
getBuildUrl,
getManifestFiles,
} from '../../libs/api-v3/buildManifest';
import forceRefresh from './../forceRefresh';
import { tavernQuest } from '../../models/group';
import { mods } from '../../models/user';
// To avoid stringifying more data then we need,
// items from `env` used on the client will have to be specified in this array
const CLIENT_VARS = ['language', 'isStaticPage', 'availableLanguages', 'translations',
'FACEBOOK_KEY', 'NODE_ENV', 'BASE_URL', 'GA_ID',
'AMAZON_PAYMENTS', 'STRIPE_PUB_KEY', 'AMPLITUDE_KEY',
'worldDmg', 'mods', 'IS_MOBILE', 'PUSHER:KEY', 'PUSHER:ENABLED'];
let env = {
getManifestFiles,
getBuildUrl,
_,
clientVars: CLIENT_VARS,
mods,
Content: shared.content,
siteVersion: forceRefresh.siteVersion,
availableLanguages: i18n.availableLanguages,
AMAZON_PAYMENTS: {
SELLER_ID: nconf.get('AMAZON_PAYMENTS:SELLER_ID'),
CLIENT_ID: nconf.get('AMAZON_PAYMENTS:CLIENT_ID'),
},
};
'NODE_ENV BASE_URL GA_ID STRIPE_PUB_KEY FACEBOOK_KEY AMPLITUDE_KEY PUSHER:KEY PUSHER:ENABLED'
.split(' ')
.forEach(key => {
env[key] = nconf.get(key);
});
module.exports = function locals (req, res, next) {
let language = _.find(i18n.availableLanguages, {code: req.language});
let isStaticPage = req.url.split('/')[1] === 'static'; // If url contains '/static/'
// Load moment.js language file only when not on static pages
language.momentLang = !isStaticPage && i18n.momentLangs[language.code] || undefined;
res.locals.habitrpg = _.assign(env, {
IS_MOBILE: /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(req.header('User-Agent')),
language,
isStaticPage,
translations: i18n.translations[language.code],
t (...args) { // stringName and vars are the allowed parameters
args.push(language.code);
return shared.i18n.t(...args);
},
// Defined here and not outside of the middleware because tavernQuest might be an
// empty object until the query to fetch it finishes
worldDmg: tavernQuest && tavernQuest.extra && tavernQuest.extra.worldDmg || {},
});
next();
};