Add Server class in nuxt

This commit is contained in:
Sébastien Chopin 2016-12-09 20:09:12 +01:00
parent 19e7e6f6cf
commit 4aa600e57a
3 changed files with 5 additions and 4 deletions

View File

@ -7,7 +7,6 @@ var _ = require('lodash')
var debug = require('debug')('nuxt:build')
var fs = require('fs')
var Nuxt = require('../')
var Server = require('../lib/server')
var chokidar = require('chokidar')
var resolve = require('path').resolve
@ -26,7 +25,7 @@ options.dev = true // Add hot reloading and watching changes
var nuxt = new Nuxt(options)
nuxt.build()
.then(() => {
var server = new Server(nuxt)
var server = new nuxt.Server(nuxt)
.listen(process.env.PORT || process.env.npm_package_config_nuxt_port, process.env.HOST || process.env.npm_package_config_nuxt_host)
listenOnConfigChanges(nuxt, server)
})

View File

@ -2,7 +2,6 @@
var fs = require('fs')
var Nuxt = require('../')
var Server = require('../lib/server')
var resolve = require('path').resolve
var rootDir = resolve(process.argv.slice(2)[0] || '.')
@ -19,7 +18,7 @@ options.dev = false // Force production mode (no webpack middlewares called)
var nuxt = new Nuxt(options)
new Server(nuxt)
new nuxt.Server(nuxt)
.listen(
process.env.PORT || process.env.npm_package_config_nuxt_port,
process.env.HOST || process.env.npm_package_config_nuxt_host

View File

@ -6,6 +6,7 @@ const fs = require('fs-extra')
const pify = require('pify')
const ansiHTML = require('ansi-html')
const serialize = require('serialize-javascript')
const Server = require('./server')
const build = require('./build')
const render = require('./render')
const generate = require('./generate')
@ -70,6 +71,8 @@ class Nuxt {
// For serving .nuxt/dist/ files
this._nuxtRegexp = /^\/_nuxt\//
this.serveStaticNuxt = pify(serveStatic(resolve(this.dir, '.nuxt', 'dist')))
// Add this.Server Class
this.Server = Server
// Add this.build
build.options.call(this) // Add build options
this.build = () => co(build.build.bind(this))