From 0954402ff317b7d80a0cb31d1de8587283b69527 Mon Sep 17 00:00:00 2001 From: localhost41 Date: Thu, 9 Jul 2026 17:02:49 -0700 Subject: [PATCH] Normalize generated QVAC base URLs --- README.md | 8 ++++++-- src/cli.ts | 9 ++++++++- test/index.test.ts | 3 +++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9ce19dc..54d9d10 100644 --- a/README.md +++ b/README.md @@ -54,10 +54,12 @@ the response text. The generated app uses `tsc` and `node` directly, so first-run installs work with pnpm 11 without approving ignored dependency build scripts. -To point at a non-default local endpoint: +To point at a non-default local endpoint, set either the server origin or an +OpenAI-compatible `/v1` base URL: ```bash QVAC_BASE_URL=http://localhost:8001 pnpm dev +QVAC_BASE_URL=http://localhost:8001/v1 pnpm dev ``` ## Troubleshooting @@ -74,10 +76,12 @@ For the default endpoint: curl http://localhost:8000/v1/chat/completions ``` -If the server is on another port or host, restart the app with `QVAC_BASE_URL`: +If the server is on another port or host, restart the app with `QVAC_BASE_URL`. +Both origin-style and OpenAI-style `/v1` base URLs are accepted: ```bash QVAC_BASE_URL=http://localhost:8001 pnpm dev +QVAC_BASE_URL=http://localhost:8001/v1 pnpm dev ``` ## Local development diff --git a/src/cli.ts b/src/cli.ts index bba71f7..e1d2a2d 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -131,6 +131,13 @@ Set \`QVAC_BASE_URL\` to use a different local endpoint. "src/index.ts", `const baseUrl = process.env.QVAC_BASE_URL ?? "http://localhost:8000"; +function chatCompletionsUrl(rawBaseUrl: string): string { + const normalized = rawBaseUrl.replace(/\\/+$/, ""); + return normalized.endsWith("/v1") + ? \`\${normalized}/chat/completions\` + : \`\${normalized}/v1/chat/completions\`; +} + interface ChatCompletionResponse { choices?: Array<{ message?: { @@ -140,7 +147,7 @@ interface ChatCompletionResponse { } async function main(): Promise { - const response = await fetch(\`\${baseUrl}/v1/chat/completions\`, { + const response = await fetch(chatCompletionsUrl(baseUrl), { method: "POST", headers: { "content-type": "application/json", diff --git a/test/index.test.ts b/test/index.test.ts index be00407..198f4a3 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -99,6 +99,9 @@ describe("create-qvac-app", () => { expect(readFileSync(join(appDirectory, "src/index.ts"), "utf8")).toContain( "QVAC_BASE_URL", ); + expect(readFileSync(join(appDirectory, "src/index.ts"), "utf8")).toContain( + 'normalized.endsWith("/v1")', + ); const packageJson = JSON.parse( readFileSync(join(appDirectory, "package.json"), "utf8"),