Skip to content

Commit d641916

Browse files
committed
feature: adding 'listen' option to restrict binding of interfaces
1 parent ef12e9a commit d641916

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

lib/cli/cli-options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export function merge(input) {
5353
appendServerDirectoryOption,
5454
handleProxyOption,
5555
handlePortsOption,
56+
handleHostOption,
5657
handleGhostModeOption,
5758
handleFilesOption,
5859
handleExtensionsOption,
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import {BsTempOptions, TransformResult} from "../cli-options";
2+
import {BsErrorLevels, BsErrorTypes} from "../../bin";
3+
4+
export function handleHostOption(incoming: BsTempOptions): TransformResult {
5+
const host: string|null = incoming.get("host");
6+
const listen: string|null = incoming.get("listen");
7+
8+
if (host && listen) {
9+
if (host !== listen) {
10+
return [incoming, [{
11+
errors: [
12+
{
13+
error: new Error("Cannot specify both `host` and `listen` options"),
14+
meta() {
15+
return [
16+
"",
17+
"Tip: Use just the `listen` option *only* if you want to bind only to a particular host.",
18+
]
19+
}
20+
}
21+
],
22+
level: BsErrorLevels.Fatal,
23+
type: BsErrorTypes.HostAndListenIncompatible
24+
}]];
25+
}
26+
27+
// whenever we have have both `host` + `listen` options,
28+
// we remove the 'host' to prevent complication further down the line
29+
return [
30+
incoming.delete('host'),
31+
[]];
32+
}
33+
34+
return [incoming, []];
35+
}

0 commit comments

Comments
 (0)