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 <noreply@anthropic.com>
This commit is contained in:
MythEclipse
2026-06-17 13:37:23 +07:00
co-authored by Claude
parent aa3f96ef2d
commit bc6edbef3e
2 changed files with 14 additions and 2 deletions
+6 -1
View File
@@ -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" &&