Skip to content

Commit

Permalink
Allow hostname to be configured via CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Dec 15, 2018
1 parent fc7abed commit c6827ab
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 56 deletions.
50 changes: 25 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
"devDependencies": {
"@types/jest": "^23.3.2",
"@types/node": "^10.0.8",
"@types/node": "^10.12.15",
"autocannon": "^3.2.0",
"express": "^4.16.3",
"jest": "^23.6.0",
Expand All @@ -72,7 +72,7 @@
},
"dependencies": {
"@types/pump": "^1.0.1",
"arg": "^2.0.1",
"arg": "^3.0.0",
"pump": "^3.0.0",
"servie-errorhandler": "^1.2.0",
"servie-finalhandler": "^1.1.0"
Expand Down
18 changes: 12 additions & 6 deletions src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ const args = arg({
'--file': String,
'--port': Number,
'--key': String,
'--hostname': String,

'-h': '--help',
'-f': '--file',
'-p': '--port',
'-H': '--hostname',
'-k': '--key'
})

const {
'--port': port = process.env.PORT || 3000,
'--port': port = Number(process.env.PORT) || 3000,
'--help': help,
'--file': file,
'--hostname': hostname = '0.0.0.0',
'--key': key = ''
} = args

Expand All @@ -31,9 +34,10 @@ if (help) {
Usage
$ servie-http -p <port> -f <script.js> -k default
Options
--file, -f A file to resolve exporting an app and serve over HTTP
--key, -k A property of "--file" with the application (${JSON.stringify(key)})
--port, -p A port number on which to start the application (${port})
--file, -f The file to resolve which exports an app to serve over HTTP
--port, -p The port number on which to start the application (${port})
--hostname, -H The hostname on which to start the application (${hostname})
--key, -k The property of "--file" exporting the application (${JSON.stringify(key)})
`)

process.exit(0)
Expand All @@ -46,8 +50,10 @@ if (typeof main !== 'function') {
throw new TypeError(`Invalid "main" function exported: ${JSON.stringify(key)}`)
}

const handler = createHandler(main)
const app = createHandler(main)

createServer(app).listen(port, hostname, (err: Error | null) => {
if (err) throw err

createServer(handler).listen(port, () => {
console.log(`Server running on http://localhost:${port}`)
})
6 changes: 1 addition & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
"strict": true,
"declaration": true,
"sourceMap": true,
"inlineSources": true,
"baseUrl": ".",
"paths": {
"arg": ["./types/arg"]
}
"inlineSources": true
}
}
18 changes: 0 additions & 18 deletions types/arg/index.d.ts

This file was deleted.

0 comments on commit c6827ab

Please sign in to comment.