Permalink
Browse files

Add port options for cli

  • Loading branch information...
amio committed May 15, 2018
1 parent 84cc8e6 commit 37965a4b497c020e12dc2d74ef1bdd0ec582277c
Showing with 18 additions and 14 deletions.
  1. +18 −14 bin/now-go
View
@@ -6,29 +6,32 @@ const go = require('../index.js')
const help = `
USAGE
now-go -c <config-file>
now-go -c <config-file-path>
-c JS or JSON config file path
-v Show version
-h Show this help message
-c, --config <path> JS or JSON config file path
-p, --port <n> Port to listen on (default: 3000)
-h, --help Show this help message
-v, --version Show version
CONFIG FILE EXAMPLE
EXAMPLE CONFIG JSON
{
"/home": "https://github.com/amio/now-go",
"/": "Yet another tinyurl service",
"*": "What are you looking for"
}
{
"/home": "https://github.com/amio/now-go",
"/": "Yet another tinyurl service",
"*": "What are you looking for"
}
`
const args = require('minimist')(process.argv.slice(2), {
alias: {
'p': 'port',
'c': 'config',
'v': 'version',
'h': 'help'
},
default: {
'c': process.env.NOW_GO_CONFIG
'c': process.env.NOW_GO_CONFIG,
'p': 3000
}
})
@@ -38,13 +41,14 @@ if (args.help) {
}
if (args.version) {
console.log('v' + require('../package.json').version)
console.log(require('../package.json').version)
process.exit()
}
if (args.config) {
const cfg = require(path.resolve(process.cwd(), args.config))
go(cfg)
const config = require(path.resolve(process.cwd(), args.config))
const options = { port: parseInt(args.port) || 3000 }
go(config, options)
} else {
console.log(help)
process.exit(1)

0 comments on commit 37965a4

Please sign in to comment.