Skip to content

Instantly share code, notes, and snippets.

@ockham
Created May 18, 2016 14:18
Show Gist options
  • Save ockham/24688ac1317220c23f5e8fbdc0d9b26a to your computer and use it in GitHub Desktop.
Save ockham/24688ac1317220c23f5e8fbdc0d9b26a to your computer and use it in GitHub Desktop.
diff --git a/server/isomorphic-routing/index.js b/server/isomorphic-routing/index.js
index e6e454c..9410c0c 100644
--- a/server/isomorphic-routing/index.js
+++ b/server/isomorphic-routing/index.js
@@ -1,7 +1,6 @@
/**
* Internal dependencies
*/
-import i18n from 'lib/mixins/i18n';
import { serverRender } from 'render';
import { createReduxStore } from 'state';
import { setSection as setSectionMiddlewareFactory } from '../../client/controller';
@@ -11,14 +10,13 @@ export function serverRouter( expressApp, setUpRoute, section ) {
expressApp.get(
route,
setUpRoute,
- setUpI18n,
combineMiddlewares(
setSectionMiddlewareFactory( section ),
...middlewares
),
serverRender
);
- }
+ };
}
function combineMiddlewares( ...middlewares ) {
@@ -26,7 +24,7 @@ function combineMiddlewares( ...middlewares ) {
req.context = getEnhancedContext( req );
applyMiddlewares( req.context, middlewares );
next();
- }
+ };
}
// TODO: Maybe merge into getDefaultContext().
@@ -52,8 +50,3 @@ function compose( ...functions ) {
next => f( composed ) // eslint-disable-line no-unused-vars
), () => {} );
}
-
-function setUpI18n( req, res, next ) {
- i18n.initialize();
- next();
-}
diff --git a/server/pages/index.js b/server/pages/index.js
index 039f2f6..3537f81 100644
--- a/server/pages/index.js
+++ b/server/pages/index.js
@@ -12,7 +12,8 @@ var config = require( 'config' ),
utils = require( 'bundler/utils' ),
sectionsModule = require( '../../client/sections' ),
serverRouter = require( 'isomorphic-routing' ).serverRouter,
- serverRender = require( 'render' ).serverRender;
+ serverRender = require( 'render' ).serverRender,
+ i18n = require( 'lib/mixins/i18n' );
var HASH_LENGTH = 10,
URL_BASE_PATH = '/calypso',
@@ -407,6 +408,15 @@ module.exports = function() {
sections
.filter( section => section.isomorphic )
.forEach( section => {
+ section.paths.forEach( path => {
+ const pathRegex = utils.pathToRegExp( path );
+
+ app.get( pathRegex, function( req, res, next ) {
+ i18n.initialize();
+ next();
+ } );
+ } );
+
sectionsModule.require( section.module )( serverRouter( app, setUpRoute, section ) );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment