2018-03-16 16:12:06 +00:00
|
|
|
import { resolve } from 'path'
|
|
|
|
import { Nuxt, Builder } from 'nuxt'
|
2017-01-11 19:13:38 +00:00
|
|
|
|
2020-11-30 22:44:04 +00:00
|
|
|
// Setup nuxt
|
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)
|
2017-10-30 10:01:23 +00:00
|
|
|
builder.build().then(() => process.emit('nuxt:build:done'))
|
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
|
|
|
|
2020-11-30 22:44:04 +00:00
|
|
|
// Add nuxt middleware
|
2018-03-16 16:12:06 +00:00
|
|
|
export default function (req, res) {
|
2017-10-30 09:11:55 +00:00
|
|
|
nuxt.render(req, res)
|
|
|
|
}
|