2017-10-30 09:11:55 +00:00
|
|
|
const resolve = require('path').resolve
|
|
|
|
const { Nuxt, Builder } = require('nuxt')
|
2017-01-11 19:13:38 +00:00
|
|
|
|
|
|
|
// Setup nuxt.js
|
2017-10-30 09:11:55 +00:00
|
|
|
let config = {}
|
2017-01-11 19:13:38 +00:00
|
|
|
try {
|
2017-10-30 09:11:55 +00:00
|
|
|
config = require('../../nuxt.config.js')
|
2017-01-11 19:13:38 +00:00
|
|
|
} catch (e) {}
|
2017-10-30 09:11:55 +00:00
|
|
|
config.rootDir = resolve(__dirname, '..', '..')
|
|
|
|
config.dev = process.env.NODE_ENV !== 'production'
|
|
|
|
|
|
|
|
const nuxt = new Nuxt(config)
|
2017-01-11 19:13:38 +00:00
|
|
|
if (config.dev) {
|
2017-10-30 09:11:55 +00:00
|
|
|
const builder = new Builder(nuxt)
|
|
|
|
builder.build()
|
2017-01-11 19:13:38 +00:00
|
|
|
} else {
|
2017-10-30 09:11:55 +00:00
|
|
|
process.nextTick(() => process.emit('nuxt:build:done'))
|
2017-01-11 19:13:38 +00:00
|
|
|
}
|
2017-10-30 09:11:55 +00:00
|
|
|
|
2017-01-11 19:13:38 +00:00
|
|
|
// Add nuxt.js middleware
|
|
|
|
module.exports = function (req, res) {
|
2017-10-30 09:11:55 +00:00
|
|
|
nuxt.render(req, res)
|
|
|
|
}
|