Skip to content

Commit 4e85ca7

Browse files
committed
Update local bind address option
1 parent 4816c87 commit 4e85ca7

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

bin/index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ var argv = yargs
1919
alias: 'p',
2020
description: 'Set port',
2121
default: 3000
22+
},
23+
host: {
24+
alias: 'H',
25+
description: 'Set host',
26+
default: '0.0.0.0'
2227
}
23-
// Disable for the moment...
24-
// host: {
25-
// alias: 'H',
26-
// description: 'Set host',
27-
// default: 'localhost'
28-
// }
2928
})
3029
.example('$0 db.json', '')
3130
.example('$0 file.js', '')
@@ -35,12 +34,15 @@ var argv = yargs
3534

3635
// Start server function
3736
function start(object, filename) {
37+
var port = process.env.PORT || argv.port
38+
var hostname = argv.host === '0.0.0.0' ? 'localhost' : argv.host
39+
3840
for (var prop in object) {
39-
console.log(chalk.grey(' http://' + host + ':' + port + '/') + chalk.cyan(prop))
41+
console.log(chalk.grey(' http://' + hostname + ':' + port + '/') + chalk.cyan(prop))
4042
}
4143

4244
console.log(
43-
'\nYou can now go to ' + chalk.grey('http://' + host + ':' + port + '/\n')
45+
'\nYou can now go to ' + chalk.grey('http://' + hostname + ':' + port + '/\n')
4446
)
4547

4648
console.log(
@@ -65,13 +67,11 @@ function start(object, filename) {
6567
var server = jsonServer.create()
6668

6769
server.use(router)
68-
server.listen(port)
70+
server.listen(port, argv.host)
6971
}
7072

7173
// Set file and port
7274
var source = argv._[0]
73-
var port = process.env.PORT || argv.port
74-
var host = 'localhost' //process.env.HOST || argv.host
7575

7676
// Say hi, load file and start server
7777
console.log(chalk.cyan('{^_^} Hi!\n'))

0 commit comments

Comments
 (0)