Skip to content

Instantly share code, notes, and snippets.

@sunderls
Created January 4, 2019 09:40
Show Gist options
  • Save sunderls/9ec617c5d87315fc00f5f301559c40d4 to your computer and use it in GitHub Desktop.
Save sunderls/9ec617c5d87315fc00f5f301559c40d4 to your computer and use it in GitHub Desktop.
use nuxt as a middleware to provide different views according to user-agent
const app = express();
app.use(router);
const configPC = require('../pc/nuxt.config.js');
const configSP = require('../sp/nuxt.config.js');
const nuxtPC = new Nuxt(configPC);
const nuxtSP = new Nuxt(configSP);
// Enable live build & reloading on dev
if (nuxtPC.options.dev) {
new Builder(nuxtPC).build()
}
if (nuxtSP.options.dev) {
new Builder(nuxtSP).build()
}
app.use((req, res, next) => {
const md = new MobileDetect(req.headers['user-agent']);
if (md.mobile()) {
nuxtSP.render(req, res);
} else {
nuxtPC.render(req, res);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment