mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
Merge branch 'api-v3' into api-v3-i18n
This commit is contained in:
2
common/dist/sprites/habitrpg-shared.css
vendored
2
common/dist/sprites/habitrpg-shared.css
vendored
File diff suppressed because one or more lines are too long
@@ -6,7 +6,7 @@ module.exports = {
|
|||||||
strings: null,
|
strings: null,
|
||||||
translations: {},
|
translations: {},
|
||||||
t: function(stringName) {
|
t: function(stringName) {
|
||||||
var clonedVars, e, locale, string, stringNotFound, vars;
|
var clonedVars, e, error, error1, locale, string, stringNotFound, vars;
|
||||||
vars = arguments[1];
|
vars = arguments[1];
|
||||||
if (_.isString(arguments[1])) {
|
if (_.isString(arguments[1])) {
|
||||||
vars = null;
|
vars = null;
|
||||||
@@ -27,9 +27,9 @@ module.exports = {
|
|||||||
clonedVars.locale = locale;
|
clonedVars.locale = locale;
|
||||||
if (string) {
|
if (string) {
|
||||||
try {
|
try {
|
||||||
return _.template(string, clonedVars);
|
return _.template(string)(clonedVars);
|
||||||
} catch (_error) {
|
} catch (error) {
|
||||||
e = _error;
|
e = error;
|
||||||
return 'Error processing the string. Please see Help > Report a Bug.';
|
return 'Error processing the string. Please see Help > Report a Bug.';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -39,13 +39,13 @@ module.exports = {
|
|||||||
stringNotFound = module.exports.translations[locale] && module.exports.translations[locale].stringNotFound;
|
stringNotFound = module.exports.translations[locale] && module.exports.translations[locale].stringNotFound;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return _.template(stringNotFound, {
|
return _.template(stringNotFound)({
|
||||||
string: stringName
|
string: stringName
|
||||||
});
|
});
|
||||||
} catch (_error) {
|
} catch (error1) {
|
||||||
e = _error;
|
e = error1;
|
||||||
return 'Error processing the string. Please see Help > Report a Bug.';
|
return 'Error processing the string. Please see Help > Report a Bug.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import mongoose from 'mongoose';
|
import mongoose from 'mongoose';
|
||||||
import autoinc from 'mongoose-id-autoinc';
|
import autoinc from 'mongoose-id-autoinc';
|
||||||
import logging from '../website/src/libs/api-v2/logging';
|
import logger from '../website/src/libs/api-v3/logger';
|
||||||
import nconf from 'nconf';
|
import nconf from 'nconf';
|
||||||
import utils from '../website/src/libs/utils';
|
import utils from '../website/src/libs/utils';
|
||||||
import repl from 'repl';
|
import repl from 'repl';
|
||||||
@@ -36,7 +36,7 @@ let improveRepl = (context) => {
|
|||||||
mongooseOptions,
|
mongooseOptions,
|
||||||
function(err) {
|
function(err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
logging.info('Connected with Mongoose');
|
logger.info('Connected with Mongoose');
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import {
|
|||||||
} from '../../../../helpers/api-unit.helper';
|
} from '../../../../helpers/api-unit.helper';
|
||||||
import analyticsService from '../../../../../website/src/libs/api-v3/analyticsService'
|
import analyticsService from '../../../../../website/src/libs/api-v3/analyticsService'
|
||||||
import nconf from 'nconf';
|
import nconf from 'nconf';
|
||||||
import attachAnalytics from '../../../../../website/src/middlewares/api-v3/analytics';
|
|
||||||
|
|
||||||
describe('analytics middleware', function() {
|
describe('analytics middleware', function() {
|
||||||
let res, req, next;
|
let res, req, next;
|
||||||
|
let pathToAnalyticsMiddleware = '../../../../../website/src/middlewares/api-v3/analytics';
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
res = generateRes();
|
res = generateRes();
|
||||||
@@ -16,17 +16,40 @@ describe('analytics middleware', function() {
|
|||||||
next = generateNext();
|
next = generateNext();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
// The nconf.get('IS_PROD') occurs when the file is required
|
||||||
|
// Since node caches IS_PROD, we have to delete it from the cache
|
||||||
|
// to test prod vs non-prod behaviors
|
||||||
|
delete require.cache[require.resolve(pathToAnalyticsMiddleware)];
|
||||||
|
});
|
||||||
|
|
||||||
it('attaches analytics object res.locals', function() {
|
it('attaches analytics object res.locals', function() {
|
||||||
|
let attachAnalytics = require(pathToAnalyticsMiddleware);
|
||||||
|
|
||||||
attachAnalytics(req, res, next);
|
attachAnalytics(req, res, next);
|
||||||
|
|
||||||
expect(res.analytics).to.exist;
|
expect(res.analytics).to.exist;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('attaches stubbed methods for non-prod environments', () => {
|
it('attaches stubbed methods for non-prod environments', () => {
|
||||||
|
sandbox.stub(nconf, 'get').withArgs('IS_PROD').returns(false);
|
||||||
|
let attachAnalytics = require(pathToAnalyticsMiddleware);
|
||||||
|
|
||||||
attachAnalytics(req, res, next);
|
attachAnalytics(req, res, next);
|
||||||
|
|
||||||
expect(res.analytics.track).to.eql(analyticsService.mockAnalyticsService.track);
|
expect(res.analytics.track).to.eql(analyticsService.mockAnalyticsService.track);
|
||||||
expect(res.analytics.trackPurchase).to.eql(analyticsService.mockAnalyticsService.trackPurchase);
|
expect(res.analytics.trackPurchase).to.eql(analyticsService.mockAnalyticsService.trackPurchase);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('attaches real methods for prod environments', () => {
|
||||||
|
sandbox.stub(nconf, 'get').withArgs('IS_PROD').returns(true);
|
||||||
|
|
||||||
|
let attachAnalytics = require(pathToAnalyticsMiddleware);
|
||||||
|
|
||||||
|
attachAnalytics(req, res, next);
|
||||||
|
|
||||||
|
expect(res.analytics.track).to.eql(analyticsService.track);
|
||||||
|
expect(res.analytics.trackPurchase).to.eql(analyticsService.trackPurchase);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ require('babel/register');
|
|||||||
// Only do the minimal amount of work before forking just in case of a dyno restart
|
// Only do the minimal amount of work before forking just in case of a dyno restart
|
||||||
var cluster = require('cluster');
|
var cluster = require('cluster');
|
||||||
var nconf = require('nconf');
|
var nconf = require('nconf');
|
||||||
var logging = require('./libs/api-v2/logging');
|
var logger = require('./libs/api-v3/logger');
|
||||||
|
|
||||||
// Initialize configuration
|
// Initialize configuration
|
||||||
var setupNconf = require('./libs/api-v3/setupNconf');
|
var setupNconf = require('./libs/api-v3/setupNconf');
|
||||||
@@ -26,7 +26,7 @@ if (cores !== 0 && cluster.isMaster && (IS_DEV || IS_PROD)) {
|
|||||||
cluster.on('disconnect', (worker) => {
|
cluster.on('disconnect', (worker) => {
|
||||||
var w = cluster.fork(); // replace the dead worker
|
var w = cluster.fork(); // replace the dead worker
|
||||||
|
|
||||||
logging.info('[%s] [master:%s] worker:%s disconnect! new worker:%s fork', new Date(), process.pid, worker.process.pid, w.process.pid);
|
logger.info('[%s] [master:%s] worker:%s disconnect! new worker:%s fork', new Date(), process.pid, worker.process.pid, w.process.pid);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
module.exports = require('./server.js');
|
module.exports = require('./server.js');
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// TODO cleanup all comments when finished API v3
|
// TODO cleanup all comments when finished API v3
|
||||||
|
|
||||||
import nconf from 'nconf';
|
import nconf from 'nconf';
|
||||||
import logging from './libs/api-v2/logging';
|
import logger from './libs/api-v3/logger';
|
||||||
import utils from './libs/utils';
|
import utils from './libs/utils';
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import http from 'http';
|
import http from 'http';
|
||||||
@@ -37,7 +37,7 @@ let mongooseOptions = !IS_PROD ? {} : {
|
|||||||
};
|
};
|
||||||
let db = mongoose.connect(nconf.get('NODE_DB_URI'), mongooseOptions, (err) => {
|
let db = mongoose.connect(nconf.get('NODE_DB_URI'), mongooseOptions, (err) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
logging.info('Connected with Mongoose');
|
logger.info('Connected with Mongoose');
|
||||||
});
|
});
|
||||||
|
|
||||||
autoinc.init(db);
|
autoinc.init(db);
|
||||||
@@ -158,7 +158,7 @@ oldApp.use(require('./middlewares/errorHandler'));
|
|||||||
|
|
||||||
server.on('request', app);
|
server.on('request', app);
|
||||||
server.listen(app.get('port'), () => {
|
server.listen(app.get('port'), () => {
|
||||||
return logging.info(`Express server listening on port ${app.get('port')}`);
|
return logger.info(`Express server listening on port ${app.get('port')}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
export default server;
|
export default server;
|
||||||
|
|||||||
Reference in New Issue
Block a user