Skip to content

Commit

Permalink
feature: adding 'listen' option to restrict binding of interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed Sep 17, 2018
1 parent ef12e9a commit d641916
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/cli/cli-options.ts
Expand Up @@ -53,6 +53,7 @@ export function merge(input) {
appendServerDirectoryOption,
handleProxyOption,
handlePortsOption,
handleHostOption,
handleGhostModeOption,
handleFilesOption,
handleExtensionsOption,
Expand Down
35 changes: 35 additions & 0 deletions lib/cli/transforms/handleHostOption.ts
@@ -0,0 +1,35 @@
import {BsTempOptions, TransformResult} from "../cli-options";
import {BsErrorLevels, BsErrorTypes} from "../../bin";

export function handleHostOption(incoming: BsTempOptions): TransformResult {
const host: string|null = incoming.get("host");
const listen: string|null = incoming.get("listen");

if (host && listen) {
if (host !== listen) {
return [incoming, [{
errors: [
{
error: new Error("Cannot specify both `host` and `listen` options"),
meta() {
return [
"",
"Tip: Use just the `listen` option *only* if you want to bind only to a particular host.",
]
}
}
],
level: BsErrorLevels.Fatal,
type: BsErrorTypes.HostAndListenIncompatible
}]];
}

// whenever we have have both `host` + `listen` options,
// we remove the 'host' to prevent complication further down the line
return [
incoming.delete('host'),
[]];
}

return [incoming, []];
}

0 comments on commit d641916

Please sign in to comment.