Skip to content

Commit

Permalink
Added custom language middleware, and tell our app to use it
Browse files Browse the repository at this point in the history
  • Loading branch information
lmarkus committed Dec 4, 2013
1 parent 548a5a1 commit 95b03fc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

var kraken = require('kraken-js'),
db = require('./lib/database'),
language = require('./lib/language'),
app = {};


Expand All @@ -21,6 +22,7 @@ app.requestStart = function requestStart(server) {

app.requestBeforeRoute = function requestBeforeRoute(server) {
// Fired before routing occurs
server.use(language());
};


Expand Down
21 changes: 21 additions & 0 deletions lib/language.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Middleware for determining the language to show the user
*/

'use strict';

module.exports = function () {

return function (req, res, next) {
//Pick up the language cookie.
var language = req.cookies.language;

//Set the locality for this response. The template will pick the appropriate bundle
if (language) {
res.locals.context = res.locals.context || {};
res.locals.context.locality = language;
}

next();
};
};

4 comments on commit 95b03fc

@BKnights
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I try to use this in your example my service just hangs. If write to console before the return statement that appears but the function is never called.

@lmarkus
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @BKnights,
Are you following the commits step by step (and are stuck in an intermediate step) or is this happening in the final code?

@BKnights
Copy link

@BKnights BKnights commented on 95b03fc Dec 19, 2013 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BKnights
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So sorry. In index.js I was calling
server.use(language);
rather than
server.use(language());

Please sign in to comment.