Skip to content

Commit 1d8a1cc

Browse files
committed
feat: add --host option to restrict listening interface
Add -H/--host option to specify which host/interface to listen on. Useful for restricting access to localhost only for security. Examples: --host 127.0.0.1 # IPv4 localhost only --host ::1 # IPv6 localhost only PR: ericc-ch#157
1 parent 343073f commit 1d8a1cc

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ The following command line options are available for the `start` command:
156156
| Option | Description | Default | Alias |
157157
| -------------- | ----------------------------------------------------------------------------- | ---------- | ----- |
158158
| --port | Port to listen on | 4141 | -p |
159+
| --host | Host/interface to listen on (e.g., 127.0.0.1 for IPv4, ::1 for IPv6) | all (::) | -H |
159160
| --verbose | Enable verbose logging | false | -v |
160161
| --account-type | Account type to use (individual, business, enterprise) | individual | -a |
161162
| --manual | Enable manual request approval | false | none |
@@ -166,6 +167,26 @@ The following command line options are available for the `start` command:
166167
| --show-token | Show GitHub and Copilot tokens on fetch and refresh | false | none |
167168
| --proxy-env | Initialize proxy from environment variables | false | none |
168169

170+
#### Usage examples with --host
171+
172+
Listen on IPv4 localhost only:
173+
174+
```sh
175+
npx copilot-api@latest start --account-type business --host 127.0.0.1
176+
```
177+
178+
Listen on IPv6 localhost only:
179+
180+
```sh
181+
npx copilot-api@latest start --account-type business --host ::1
182+
```
183+
184+
Default (listen on all interfaces):
185+
186+
```sh
187+
npx copilot-api@latest start --account-type business
188+
```
189+
169190
### Auth Command Options
170191

171192
| Option | Description | Default | Alias |

src/start.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { server } from "./server"
1616

1717
interface RunServerOptions {
1818
port: number
19+
host?: string
1920
verbose: boolean
2021
accountType: string
2122
manual: boolean
@@ -117,6 +118,7 @@ export async function runServer(options: RunServerOptions): Promise<void> {
117118
serve({
118119
fetch: server.fetch as ServerHandler,
119120
port: options.port,
121+
hostname: options.host,
120122
})
121123
}
122124

@@ -138,6 +140,12 @@ export const start = defineCommand({
138140
default: false,
139141
description: "Enable verbose logging",
140142
},
143+
host: {
144+
alias: "H",
145+
type: "string",
146+
description:
147+
"Host/interface to listen on (e.g., 127.0.0.1 for IPv4 localhost, ::1 for IPv6 localhost)",
148+
},
141149
"account-type": {
142150
alias: "a",
143151
type: "string",
@@ -193,6 +201,7 @@ export const start = defineCommand({
193201

194202
return runServer({
195203
port: Number.parseInt(args.port, 10),
204+
host: args.host,
196205
verbose: args.verbose,
197206
accountType: args["account-type"],
198207
manual: args.manual,

0 commit comments

Comments
 (0)