Skip to content
This repository was archived by the owner on Oct 30, 2018. It is now read-only.

Mixing in static context into req's context #1378

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions lib/app/middleware/mojito-contextualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/


/*jslint node:true, nomen:true*/
/*jslint node:true, nomen:true, forin: true*/

/**
@module mojito-contextualizer
Expand Down Expand Up @@ -133,13 +133,14 @@ function RequestContextualizer() {

return function middlewareMojitoContextualizer(req, res, next) {


if (!defaultLang && req.app && req.app.mojito) {
defaultLang = (req.app.mojito.context && req.app.mojito.context.lang) ||
DEFAULT_LANG;
}

var query = url.parse(req.url, true).query || {};
var c,
query = url.parse(req.url, true).query || {},
staticContext = req.app.mojito.store.getStaticContext();

if (!req.context) {
req.context = {};
Expand All @@ -160,10 +161,13 @@ function RequestContextualizer() {
req.context.flavor = query.flavor || '';
req.context.tz = query.tz || '';

// debug('detected lang: ' + req.context.lang, 'debug',
// 'request-contextualizer');
// debug('detected device: ' + req.context.device, 'debug',
// 'request-contextualizer');
// Mix in static context, with req's context taking precedence.
for (c in staticContext) {
if (!req.context[c]) {
req.context[c] = staticContext[c];
}
}

next();
};
}
Expand Down