mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
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
This commit is contained in:
parent
19f1125520
commit
c4a22abb4c
|
@ -10,12 +10,11 @@ process.env.NODE_ENV = process.env.NODE_ENV || 'production'
|
||||||
const argv = parseArgs(process.argv.slice(2), {
|
const argv = parseArgs(process.argv.slice(2), {
|
||||||
alias: {
|
alias: {
|
||||||
h: 'help',
|
h: 'help',
|
||||||
|
H: 'hostname',
|
||||||
p: 'port'
|
p: 'port'
|
||||||
},
|
},
|
||||||
boolean: ['h'],
|
boolean: ['h'],
|
||||||
default: {
|
default: { p: 3000 }
|
||||||
p: 3000
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (argv.help) {
|
if (argv.help) {
|
||||||
|
@ -33,6 +32,7 @@ if (argv.help) {
|
||||||
|
|
||||||
Options
|
Options
|
||||||
--port, -p A port number on which to start the application
|
--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
|
--help, -h Displays this message
|
||||||
`)
|
`)
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
|
@ -47,10 +47,10 @@ if (!existsSync(resolve(dir, '.next', 'BUILD_ID'))) {
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
srv.start(argv.port)
|
srv.start(argv.port, argv.hostname)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (!process.env.NOW) {
|
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) => {
|
.catch((err) => {
|
||||||
|
|
|
@ -123,14 +123,18 @@ export default class Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async start (port) {
|
async start (port, hostname) {
|
||||||
await this.prepare()
|
await this.prepare()
|
||||||
this.http = http.createServer(this.getRequestHandler())
|
this.http = http.createServer(this.getRequestHandler())
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
// This code catches EADDRINUSE error if the port is already in use
|
// This code catches EADDRINUSE error if the port is already in use
|
||||||
this.http.on('error', reject)
|
this.http.on('error', reject)
|
||||||
this.http.on('listening', () => resolve())
|
this.http.on('listening', () => resolve())
|
||||||
this.http.listen(port)
|
if (hostname && typeof hostname !== 'boolean') {
|
||||||
|
this.http.listen(port, hostname)
|
||||||
|
} else {
|
||||||
|
this.http.listen(port)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue