Nuxt/lib/server.js

34 lines
576 B
JavaScript
Raw Normal View History

'use strict'
const http = require('http')
class Server {
constructor (nuxt) {
this.nuxt = nuxt
this.server = http.createServer(this.render.bind(this))
return this
}
render (req, res) {
this.nuxt.render(req, res)
return this
}
listen (port, host) {
host = host || 'localhost'
port = port || 3000
this.server.listen(port, host, () => {
2016-12-08 15:41:20 +00:00
console.log('Ready on http://%s:%s', host, port) // eslint-disable-line no-console
})
return this
}
2016-12-09 22:07:18 +00:00
close (cb) {
return this.server.close(cb)
}
}
2017-01-11 19:14:59 +00:00
export default Server