2016-11-09 22:59:41 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const http = require('http')
|
|
|
|
|
|
|
|
class Server {
|
|
|
|
|
|
|
|
constructor (nuxt) {
|
2016-11-16 17:41:09 +00:00
|
|
|
this.nuxt = nuxt
|
|
|
|
this.server = http.createServer(this.render.bind(this))
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
render (req, res) {
|
|
|
|
this.nuxt.render(req, res)
|
2016-11-09 22:59:41 +00:00
|
|
|
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
|
2016-11-09 22:59:41 +00:00
|
|
|
})
|
2016-11-16 17:41:09 +00:00
|
|
|
return this
|
2016-11-09 22:59:41 +00:00
|
|
|
}
|
|
|
|
|
2016-12-09 22:07:18 +00:00
|
|
|
close (cb) {
|
|
|
|
return this.server.close(cb)
|
|
|
|
}
|
|
|
|
|
2016-11-09 22:59:41 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 19:14:59 +00:00
|
|
|
export default Server
|