Commit c4a22abb authored by Jesse Hattabaugh's avatar Jesse Hattabaugh Committed by Tim Neutkens

adding hostname argument to CLI (#1017)

* adding hostname argument to CLI

* using -H instead of -hn

* removing hostname default

* checking that hostname has a truthy value that's not a boolean

* making the log message match the hostname

* oops
parent 19f11255
......@@ -10,12 +10,11 @@ process.env.NODE_ENV = process.env.NODE_ENV || 'production'
const argv = parseArgs(process.argv.slice(2), {
alias: {
h: 'help',
H: 'hostname',
p: 'port'
},
boolean: ['h'],
default: {
p: 3000
}
default: { p: 3000 }
})
if (argv.help) {
......@@ -33,6 +32,7 @@ if (argv.help) {
Options
--port, -p A port number on which to start the application
--hostname, -H Hostname on which to start the application
--help, -h Displays this message
`)
process.exit(0)
......@@ -47,10 +47,10 @@ if (!existsSync(resolve(dir, '.next', 'BUILD_ID'))) {
process.exit(1)
}
srv.start(argv.port)
srv.start(argv.port, argv.hostname)
.then(() => {
if (!process.env.NOW) {
console.log(`> Ready on http://localhost:${argv.port}`)
console.log(`> Ready on http://${argv.hostname && typeof argv.hostname !== 'boolean' ? argv.hostname : 'localhost'}:${argv.port}`)
}
})
.catch((err) => {
......
......@@ -123,14 +123,18 @@ export default class Server {
}
}
async start (port) {
async start (port, hostname) {
await this.prepare()
this.http = http.createServer(this.getRequestHandler())
await new Promise((resolve, reject) => {
// This code catches EADDRINUSE error if the port is already in use
this.http.on('error', reject)
this.http.on('listening', () => resolve())
this.http.listen(port)
if (hostname && typeof hostname !== 'boolean') {
this.http.listen(port, hostname)
} else {
this.http.listen(port)
}
})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment