-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added custom language middleware, and tell our app to use it
- Loading branch information
lmarkus
committed
Dec 4, 2013
1 parent
548a5a1
commit 95b03fc
Showing
2 changed files
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; | ||
}; |
95b03fc
There was a problem hiding this comment.
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.
95b03fc
There was a problem hiding this comment.
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?
95b03fc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
95b03fc
There was a problem hiding this comment.
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());