mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
deprecating use of templates.setGlobal on server side in favour of passing in api.config into res.locals (still needs work)
This commit is contained in:
@@ -7,9 +7,8 @@ var pkg = require('./../../package.json'),
|
||||
|
||||
var apiController = {};
|
||||
|
||||
|
||||
apiController.getConfig = function(req, res, next, callback) {
|
||||
var config = require('../../public/config.json');
|
||||
apiController.getConfig = function(req, res, next) {
|
||||
var config = require('./../../public/config.json');
|
||||
|
||||
config.version = pkg.version;
|
||||
config.postDelay = meta.config.postDelay;
|
||||
@@ -35,23 +34,23 @@ apiController.getConfig = function(req, res, next, callback) {
|
||||
config.environment = process.env.NODE_ENV;
|
||||
|
||||
if (!req.user) {
|
||||
return res.json(200, config);
|
||||
if (res.locals.isAPI) {
|
||||
res.json(200, config);
|
||||
} else {
|
||||
next(null, config);
|
||||
}
|
||||
}
|
||||
|
||||
if(req.user) {
|
||||
user.getSettings(req.user.uid, function(err, settings) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
config.usePagination = settings.usePagination;
|
||||
config.topicsPerPage = settings.topicsPerPage;
|
||||
config.postsPerPage = settings.postsPerPage;
|
||||
|
||||
if (callback) {
|
||||
callback(err, config);
|
||||
} else {
|
||||
if (res.locals.isAPI) {
|
||||
res.json(200, config);
|
||||
} else {
|
||||
next(err, config);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,7 +13,12 @@ var app,
|
||||
plugins = require('./../plugins'),
|
||||
meta = require('./../meta'),
|
||||
translator = require('./../../public/src/translator'),
|
||||
user = require('./../user');
|
||||
user = require('./../user'),
|
||||
|
||||
controllers = {
|
||||
api: require('./../controllers/api')
|
||||
};
|
||||
|
||||
|
||||
middleware.authenticate = function(req, res, next) {
|
||||
if(!req.user) {
|
||||
@@ -87,6 +92,12 @@ middleware.buildHeader = function(req, res, next) {
|
||||
res.locals.renderHeader = true;
|
||||
next();
|
||||
},
|
||||
function(next) {
|
||||
controllers.api.getConfig(req, res, function(err, config) {
|
||||
res.locals.config = config;
|
||||
next();
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
// this is slower than the original implementation because the rendered template is not cached
|
||||
// but I didn't bother to fix this because we will deprecate [filter:footer.build] in favour of the widgets system by 0.4x
|
||||
@@ -158,6 +169,12 @@ middleware.renderHeader = function (options, callback) {
|
||||
'"': '"'
|
||||
};
|
||||
|
||||
for (var key in options.res.locals.config) {
|
||||
if (options.res.locals.config.hasOwnProperty(key)) {
|
||||
templateValues[key] = options.res.locals.config[key];
|
||||
}
|
||||
}
|
||||
|
||||
var uid = '0';
|
||||
|
||||
templateValues.metaTags = defaultMetaTags.concat(options.res.locals.metaTags || []).map(function(tag) {
|
||||
|
||||
Reference in New Issue
Block a user