mirror of
https://github.com/typicode/json-server.git
synced 2025-07-28 20:52:08 +08:00
Added host option
This commit is contained in:
10
bin/index.js
10
bin/index.js
@ -19,6 +19,11 @@ var argv = yargs
|
|||||||
alias: 'p',
|
alias: 'p',
|
||||||
description: 'Set port',
|
description: 'Set port',
|
||||||
default: 3000
|
default: 3000
|
||||||
|
},
|
||||||
|
host: {
|
||||||
|
alias: 'H',
|
||||||
|
description: 'Set host',
|
||||||
|
default: 'localhost'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.example('$0 db.json', '')
|
.example('$0 db.json', '')
|
||||||
@ -30,11 +35,11 @@ var argv = yargs
|
|||||||
// Start server function
|
// Start server function
|
||||||
function start(object, filename) {
|
function start(object, filename) {
|
||||||
for (var prop in object) {
|
for (var prop in object) {
|
||||||
console.log(chalk.grey(' http://localhost:' + port + '/') + chalk.cyan(prop))
|
console.log(chalk.grey(' http://' + host + ':' + port + '/') + chalk.cyan(prop))
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
'\nYou can now go to ' + chalk.grey('http://localhost:' + port + '/\n')
|
'\nYou can now go to ' + chalk.grey('http://' + host + ':' + port + '/\n')
|
||||||
)
|
)
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
@ -65,6 +70,7 @@ function start(object, filename) {
|
|||||||
// Set file and port
|
// Set file and port
|
||||||
var source = argv._[0]
|
var source = argv._[0]
|
||||||
var port = process.env.PORT || argv.port
|
var port = process.env.PORT || argv.port
|
||||||
|
var host = process.env.HOST || argv.host
|
||||||
|
|
||||||
// Say hi, load file and start server
|
// Say hi, load file and start server
|
||||||
console.log(chalk.cyan('{^_^} Hi!\n'))
|
console.log(chalk.cyan('{^_^} Hi!\n'))
|
||||||
|
Reference in New Issue
Block a user