Nuxt/examples/with-feathers/src/middleware/nuxt.js

24 lines
565 B
JavaScript
Raw Normal View History

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
let config = {}
2017-01-11 19:13:38 +00:00
try {
config = require('../../nuxt.config.js')
2017-01-11 19:13:38 +00:00
} catch (e) {}
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) {
const builder = new Builder(nuxt)
builder.build().then(() => process.emit('nuxt:build:done'))
2017-01-11 19:13:38 +00:00
} else {
process.nextTick(() => process.emit('nuxt:build:done'))
2017-01-11 19:13:38 +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) {
nuxt.render(req, res)
}