diff --git a/README.md b/README.md index 0d36c13c..2a956656 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,7 @@ The following command line options are available for the `start` command: | Option | Description | Default | Alias | | -------------- | ----------------------------------------------------------------------------- | ---------- | ----- | | --port | Port to listen on | 4141 | -p | +| --host | Host/interface to listen on (e.g., 127.0.0.1 for IPv4, ::1 for IPv6) | all (::) | -h | | --verbose | Enable verbose logging | false | -v | | --account-type | Account type to use (individual, business, enterprise) | individual | -a | | --manual | Enable manual request approval | false | none | @@ -164,6 +165,24 @@ The following command line options are available for the `start` command: | --show-token | Show GitHub and Copilot tokens on fetch and refresh | false | none | | --proxy-env | Initialize proxy from environment variables | false | none | + +#### Usage examples with --host + +Listen on IPv4 localhost only: +```sh +npx copilot-api@latest start --account-type business --host 127.0.0.1 +``` + +Listen on IPv6 localhost only: +```sh +npx copilot-api@latest start --account-type business --host ::1 +``` + +Default (listen on all interfaces): +```sh +npx copilot-api@latest start --account-type business +``` + ### Auth Command Options | Option | Description | Default | Alias | diff --git a/src/start.ts b/src/start.ts index 14abbbdf..98307c2d 100644 --- a/src/start.ts +++ b/src/start.ts @@ -16,6 +16,7 @@ import { server } from "./server" interface RunServerOptions { port: number + host?: string verbose: boolean accountType: string manual: boolean @@ -65,6 +66,7 @@ export async function runServer(options: RunServerOptions): Promise { ) const serverUrl = `http://localhost:${options.port}` + const hostForUrl = options.host || 'localhost'; if (options.claudeCode) { invariant(state.models, "Models should be loaded by now") @@ -117,6 +119,7 @@ export async function runServer(options: RunServerOptions): Promise { serve({ fetch: server.fetch as ServerHandler, port: options.port, + hostname: options.host || undefined, // undefined falls back to system default (all interfaces) }) } @@ -138,6 +141,12 @@ export const start = defineCommand({ default: false, description: "Enable verbose logging", }, + host: { + alias: "h", + type: "string", + description: + "Host/interface to listen on (e.g., 127.0.0.1 for IPv4 localhost, ::1 for IPv6 localhost)", + }, "account-type": { alias: "a", type: "string", @@ -193,6 +202,7 @@ export const start = defineCommand({ return runServer({ port: Number.parseInt(args.port, 10), + host: args.host, verbose: args.verbose, accountType: args["account-type"], manual: args.manual,