mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Use minimist string option for hostname (#1090)
* Use minimist string option * Consistently use --hostname * Code style * Show hostname
This commit is contained in:
parent
c4a22abb4c
commit
f93bacfaba
|
@ -14,9 +14,15 @@ const argv = parseArgs(process.argv.slice(2), {
|
||||||
p: 'port'
|
p: 'port'
|
||||||
},
|
},
|
||||||
boolean: ['h'],
|
boolean: ['h'],
|
||||||
|
string: ['H'],
|
||||||
default: { p: 3000 }
|
default: { p: 3000 }
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (argv.hostname === '') {
|
||||||
|
console.error(`> Provided hostname argument has no value`)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
if (argv.help) {
|
if (argv.help) {
|
||||||
console.log(`
|
console.log(`
|
||||||
Description
|
Description
|
||||||
|
@ -50,11 +56,10 @@ if (!existsSync(resolve(dir, '.next', 'BUILD_ID'))) {
|
||||||
srv.start(argv.port, argv.hostname)
|
srv.start(argv.port, argv.hostname)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (!process.env.NOW) {
|
if (!process.env.NOW) {
|
||||||
console.log(`> Ready on http://${argv.hostname && typeof argv.hostname !== 'boolean' ? argv.hostname : 'localhost'}:${argv.port}`)
|
console.log(`> Ready on http://${argv.hostname ? argv.hostname : 'localhost'}:${argv.port}`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -130,11 +130,7 @@ export default class Server {
|
||||||
// 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())
|
||||||
if (hostname && typeof hostname !== 'boolean') {
|
this.http.listen(port, hostname)
|
||||||
this.http.listen(port, hostname)
|
|
||||||
} else {
|
|
||||||
this.http.listen(port)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue