Skip to content

Commit 7c9139b

Browse files
committed
fix: optional proxy env
1 parent 025d284 commit 7c9139b

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ The following command line options are available for the `start` command:
162162
| --github-token | Provide GitHub token directly (must be generated using the `auth` subcommand) | none | -g |
163163
| --claude-code | Generate a command to launch Claude Code with Copilot API config | false | -c |
164164
| --show-token | Show GitHub and Copilot tokens on fetch and refresh | false | none |
165+
| --proxy-env | Initialize proxy from environment variables | false | none |
165166

166167
### Auth Command Options
167168

@@ -251,6 +252,9 @@ npx copilot-api@latest debug
251252

252253
# Display debug information in JSON format
253254
npx copilot-api@latest debug --json
255+
256+
# Initialize proxy from environment variables (HTTP_PROXY, HTTPS_PROXY, etc.)
257+
npx copilot-api@latest start --proxy-env
254258
```
255259

256260
## Using the Usage Viewer

src/main.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { defineCommand, runMain } from "citty"
55
import { auth } from "./auth"
66
import { checkUsage } from "./check-usage"
77
import { debug } from "./debug"
8-
import { initProxyFromEnv } from "./lib/proxy"
98
import { start } from "./start"
109

1110
const main = defineCommand({
@@ -17,6 +16,4 @@ const main = defineCommand({
1716
subCommands: { auth, start, "check-usage": checkUsage, debug },
1817
})
1918

20-
initProxyFromEnv()
21-
2219
await runMain(main)

src/start.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { serve, type ServerHandler } from "srvx"
77
import invariant from "tiny-invariant"
88

99
import { ensurePaths } from "./lib/paths"
10+
import { initProxyFromEnv } from "./lib/proxy"
1011
import { generateEnvScript } from "./lib/shell"
1112
import { state } from "./lib/state"
1213
import { setupCopilotToken, setupGitHubToken } from "./lib/token"
@@ -23,9 +24,14 @@ interface RunServerOptions {
2324
githubToken?: string
2425
claudeCode: boolean
2526
showToken: boolean
27+
proxyEnv: boolean
2628
}
2729

2830
export async function runServer(options: RunServerOptions): Promise<void> {
31+
if (options.proxyEnv) {
32+
initProxyFromEnv()
33+
}
34+
2935
if (options.verbose) {
3036
consola.level = 5
3137
consola.info("Verbose logging enabled")
@@ -173,6 +179,11 @@ export const start = defineCommand({
173179
default: false,
174180
description: "Show GitHub and Copilot tokens on fetch and refresh",
175181
},
182+
"proxy-env": {
183+
type: "boolean",
184+
default: false,
185+
description: "Initialize proxy from environment variables",
186+
},
176187
},
177188
run({ args }) {
178189
const rateLimitRaw = args["rate-limit"]
@@ -190,6 +201,7 @@ export const start = defineCommand({
190201
githubToken: args["github-token"],
191202
claudeCode: args["claude-code"],
192203
showToken: args["show-token"],
204+
proxyEnv: args["proxy-env"],
193205
})
194206
},
195207
})

0 commit comments

Comments
 (0)