diff --git a/lib/common/options.js b/lib/common/options.js index 0fc0beba43..3dd367bcc4 100755 --- a/lib/common/options.js +++ b/lib/common/options.js @@ -225,6 +225,7 @@ Options.defaults = { css: [], modules: [], layouts: {}, + serverInstance: null, serverMiddleware: [], ErrorPage: null, loading: { diff --git a/lib/core/renderer.js b/lib/core/renderer.js index a2e1595eb2..1bc4e7b66a 100644 --- a/lib/core/renderer.js +++ b/lib/core/renderer.js @@ -39,8 +39,16 @@ export default class Renderer extends Tapable { this.webpackDevMiddleware = null this.webpackHotMiddleware = null - // Create new connect instance - this.app = connect() + if (typeof this.options.serverInstance === 'string') { + // Resolve the module from rootDir + this.app = require(this.nuxt.resolvePath(this.options.serverInstance))() + } else if (this.options.serverInstance instanceof Function) { + // Use the instance directly + this.app = this.options.serverInstance + } else { + // Create new connect instance + this.app = connect() + } // Renderer runtime resources this.resources = {