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:
+6
-1
@@ -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" &&
|
||||
|
||||
+8
-1
@@ -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" &&
|
||||
|
||||
Reference in New Issue
Block a user