From 22d5424cafbb095a225282ef8db8356d554a8fdb Mon Sep 17 00:00:00 2001 From: Hana Shiro Date: Fri, 25 Aug 2017 07:27:02 +0800 Subject: [PATCH] Allow custom HTTP server instance from user --- lib/common/options.js | 1 + lib/core/renderer.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) 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 = {