Created
January 4, 2019 09:40
-
-
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
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
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