Allow custom HTTP server instance from user

This commit is contained in:
Hana Shiro 2017-08-25 07:27:02 +08:00
parent cafc94d9f9
commit 22d5424caf
2 changed files with 11 additions and 2 deletions

View File

@ -225,6 +225,7 @@ Options.defaults = {
css: [], css: [],
modules: [], modules: [],
layouts: {}, layouts: {},
serverInstance: null,
serverMiddleware: [], serverMiddleware: [],
ErrorPage: null, ErrorPage: null,
loading: { loading: {

View File

@ -39,8 +39,16 @@ export default class Renderer extends Tapable {
this.webpackDevMiddleware = null this.webpackDevMiddleware = null
this.webpackHotMiddleware = null this.webpackHotMiddleware = null
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 // Create new connect instance
this.app = connect() this.app = connect()
}
// Renderer runtime resources // Renderer runtime resources
this.resources = { this.resources = {