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

23 lines
555 B
JavaScript
Raw Normal View History

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