refactor: extract test page to shared module, use env var for API key

This commit is contained in:
MythEclipse committed 2026-06-24 18:18:49 +07:00
1 parent d5f8dfc1d7
commit 6b9dd3770e
4 files changed
+307 -19

No files matched your search

+3 -3
View File
@@ -29,7 +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 testApiHtmlRaw from "./test-api-content";
import { getTestPageHtml } from "../src/lib/test-page";
// ─── Configuration ──────────────────────────────────────────────────────────────
@@ -42,7 +42,7 @@ const RELAY_VERSION = "1.0.0";
// ─── API Key Authentication ─────────────────────────────────────────────────────
const API_KEY = "sk-dummy-key";
const API_KEY = process.env.API_KEY ?? "sk-dummy-key";
function requireAuth(req: Request): Response | null {
const header = req.headers.get("authorization") ?? req.headers.get("x-api-key") ?? "";
@@ -382,7 +382,7 @@ export default {
// Static routes — show index only when no relay target is requested
if (url.pathname === "/health") return handleHealth();
if (url.pathname === "/docs" || url.pathname === "/test") {
return new Response(testApiHtmlRaw, {
return new Response(getTestPageHtml(), {
headers: { "Content-Type": "text/html; charset=utf-8" },
});
}
+1 -2
View File
@@ -1,2 +1 @@
export default "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Edge Proxy — API Test</title>\n <style>\n *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }\n body { font-family: system-ui, -apple-system, sans-serif; background: #0d1117; color: #e1e4e8; padding: 1.5rem; }\n main { max-width: 960px; margin: 0 auto; }\n h1 { font-size: 1.5rem; colorLine truncated
</script>\n</body>\n</html>\n";
export { getTestPageHtml as default } from "../src/lib/test-page";