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

24 lines
543 B
JavaScript
Raw Normal View History

const resolve = require('path').resolve
const { Nuxt, Builder } = require('nuxt')
2017-01-11 19:13:38 +00:00
// Setup nuxt.js
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()
2017-01-11 19:13:38 +00:00
} else {
process.nextTick(() => process.emit('nuxt:build:done'))
2017-01-11 19:13:38 +00:00
}
2017-01-11 19:13:38 +00:00
// Add nuxt.js middleware
module.exports = function (req, res) {
nuxt.render(req, res)
}