diff --git a/lib/render.js b/lib/render.js index d026a6d4fb..4e9cc52989 100644 --- a/lib/render.js +++ b/lib/render.js @@ -4,6 +4,10 @@ const { urlJoin } = require('./utils') const { getContext } = require('./utils') exports.render = function (req, res) { + if (!this.renderer && !this.dev) { + console.error('> No build files found, please run `nuxt build` before launching `nuxt start`') + process.exit(1) + } if (!this.renderer) { setTimeout(() => { this.render(req, res) @@ -87,3 +91,33 @@ exports.renderRoute = function (url, context = {}) { } }) } + +// Function used to do dom checking via jsdom +exports.renderAndGetWindow = function renderAndGetWindow (jsdom, url) { + const virtualConsole = jsdom.createVirtualConsole().sendTo(console) + url = url || 'http://localhost:3000' + return new Promise((resolve, reject) => { + jsdom.env({ + url: url, + features: { + FetchExternalResources: ['script', 'link'], + ProcessExternalResources: ['script'] + }, + virtualConsole, + done (err, window) { + if (err) return reject(err) + // If Nuxt could not be loaded (error from the server-side) + if (!window.__NUXT__) { + return reject({ + message: 'Could not load the nuxt app', + body: window.document.getElementsByTagName('body')[0].innerHTML + }) + } + // Used by nuxt.js to say when the components are loaded and the app ready + window.onNuxtReady(() => { + resolve(window) + }) + } + }) + }) +}