Nuxt/examples/with-feathers/src/middleware/nuxt.js
2020-11-30 23:44:04 +01:00

24 lines
565 B
JavaScript

import { resolve } from 'path'
import { Nuxt, Builder } from 'nuxt'
// Setup nuxt
let config = {}
try {
config = require('../../nuxt.config.js')
} catch (e) {}
config.rootDir = resolve(__dirname, '..', '..')
config.dev = process.env.NODE_ENV !== 'production'
const nuxt = new Nuxt(config)
if (config.dev) {
const builder = new Builder(nuxt)
builder.build().then(() => process.emit('nuxt:build:done'))
} else {
process.nextTick(() => process.emit('nuxt:build:done'))
}
// Add nuxt middleware
export default function (req, res) {
nuxt.render(req, res)
}