From bc6edbef3e84319d56e0e6fc2f112399cfaadd70 Mon Sep 17 00:00:00 2001 From: MythEclipse Date: Wed, 17 Jun 2026 13:37:23 +0700 Subject: [PATCH] fix: serve test-api.html at /docs on Vercel and Worker deployments Update api/relay.ts (Vercel entry point) and src/worker.ts (Cloudflare Workers entry point) to serve the interactive API test console at /docs and /test, replacing the old inline docs page. api/relay.ts uses Bun's HTML import (bundled inline at build time) since filesystem access is unavailable in Vercel serverless runtime. Co-Authored-By: Claude --- api/relay.ts | 7 ++++++- src/worker.ts | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/api/relay.ts b/api/relay.ts index 4c07085..dcddebb 100644 --- a/api/relay.ts +++ b/api/relay.ts @@ -29,6 +29,7 @@ import { createRateLimiter } from "../src/middleware/rate-limiter"; import { logRelayEvent } from "../src/middleware/logger"; import { handleChatCompletion, listModels } from "../src/lib/ai-proxy"; import { handleAnthropicMessages } from "../src/lib/anthropic-proxy"; +import testApiHtml from "../public/test-api.html"; // ─── Configuration ────────────────────────────────────────────────────────────── @@ -380,7 +381,11 @@ export default { // Static routes — show index only when no relay target is requested if (url.pathname === "/health") return handleHealth(); - if (url.pathname === "/docs") return handleDocs(); + if (url.pathname === "/docs" || url.pathname === "/test") { + return new Response(testApiHtml, { + headers: { "Content-Type": "text/html; charset=utf-8" }, + }); + } if ( url.pathname === "/" && req.method === "GET" && diff --git a/src/worker.ts b/src/worker.ts index 239e490..2c924a4 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -386,7 +386,14 @@ export default { const url = new URL(req.url); if (url.pathname === "/health") return handleHealth(); - if (url.pathname === "/docs") return handleDocs(); + if (url.pathname === "/docs" || url.pathname === "/test") { + const file = Bun.file("public/test-api.html"); + const exists = await file.exists(); + return new Response(exists ? file : "Not found", { + status: exists ? 200 : 404, + headers: { "Content-Type": "text/html; charset=utf-8" }, + }); + } if ( url.pathname === "/" && req.method === "GET" &&