Q:

Best practice for language sub domains in an Express server?

So I have a Node/Express server set up, and we are making the transition from subdirectories to sub domains for localisation, eg:
es.example.com       // old way
www.example.com/es   // new way

Doing this for a variety of reasons, but mostly to facilitate the preservation of JWT login state across the internationalised content. What is the best practice for allowing this in express when declaring routes?
If I have a route simply set up like this:
app.use('/search')

Then when I try to hit a route, eg www.example.com/es/search, I will just be redirected to www.example.com/search, the es will be stripped. However, this can be fixed like this:
app.use('*/search')

I'm sure this must have some negative implications though? How do people typically allow for prefixes in routes via Express?

A:

If you are using Express 4, you can use modular routes to create a set of routes that can then be shared across your different locale codes. This will ensure that you only apply routes to specific locale codes rather than all possible words prior to your route (such as /fakePath/search).
// routes.js
var express = require('express');
var router = express.Router();

router.use('/search');

module.exports = router; 

// index.js
var routes = require('./routes');

app.use('/en', routes);
app.use('/es', routes);
// ...

