Commit Graph
12 Commits
Author SHA1 Message Date
MythEclipse cb6191902e fix: critical bugs, serverless stability, and security hardening
Bug Fixes:
- Fix rate limiter API mismatch: check() -> checkAsync() in index.ts, worker.ts, api/relay.ts
- Fix WebSocket SSRF silent drop: return error Response instead of undefined
- Fix isDevMode() default: changed from true to false (production-safe)
- Fix process.env -> env bindings in worker.ts requireAuth for Cloudflare Workers
- Fix Bun.file() crash in Workers: add try/catch with fallback
- Fix Bun.CryptoHasher -> Web Crypto API in mimo-auth.ts for Workers compat

Architecture:
- Add public methods to ProxyPool (getEntryAtIndex, getProxyUrlAtIndex, getCurrentIndex, setCurrentIndex) to remove all 'as any' casts in SessionProxyPool
- Add addProxy() method for manual proxy management
- Add loadAsync(), tryLoadAsync(), loadFromString() to ProxyPool

Serverless Stability:
- Add optional DNS rebinding protection via SSRF_DNS_CHECK env flag
- CORS cache now auto-invalidates when CORS_ORIGIN env changes
- Rate limiter max-size eviction (10k keys) prevents unbounded memory growth

Tests:
- Fix type assertions in test files (body as Record<string, unknown>)
- All 153 tests pass, typecheck clean
2026-06-19 18:10:49 +07:00
MythEclipseandClaude 778180a5dc fix: inline test-api.html as TypeScript string export for Vercel
Bun import of .html files returns HTMLBundle (not a string) in Vercel's
serverless environment, and Bun.file() has no filesystem access there.
Copy the HTML content into api/test-api-content.ts as an escaped string
export, then import it in api/relay.ts — Bun bundler inlines it.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-17 14:14:13 +07:00
MythEclipseandClaude f8fd18612b fix: use Bun.file().text() at module scope to inline test-api.html
Bun HTML import returns HTMLBundle object on Vercel serverless, which
renders as '[object HTMLBundle]'. Using Bun.file().text() at top-level
module scope ensures Bun bundler inlines the raw string at build time.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-17 13:54:13 +07:00
MythEclipseandClaude bcba2c5386 fix: use text import for test-api.html in Vercel deployment
Bun HTML import returns HTMLBundle object, not a string — Vercel
renders it as '[object HTMLBundle]'. Use 'with { type: "text" }'
to import as raw string so it renders properly.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-17 13:51:04 +07:00
MythEclipseandClaude bc6edbef3e 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>
2026-06-17 13:37:23 +07:00
MythEclipseandClaude Fable 5 47b85fb396 chore: use hardcoded dummy API key
- Replace env-based API_KEY with sk-dummy-key hardcoded
- All entry points use same key: Authorization: Bearer sk-dummy-key
- Simplifies usage for library/client consumption

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 00:59:01 +07:00
MythEclipseandClaude Fable 5 c0a02279bd feat: add API key authentication for AI proxy endpoints
- Add API_KEY config (env var) to all entry points
- requireAuth helper checks Authorization: Bearer or x-api-key header
- Auth applied to /v1/chat/completions, /v1/messages, /v1/models
- When API_KEY is empty/unset, auth is disabled (backward compatible)
- Update wrangler.toml with API_KEY variable documentation

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 00:56:18 +07:00
MythEclipseandClaude Fable 5 2fead57d0f fix: use MODEL_ROUTES directly for Anthropic proxy routing
Remove the ANTHROPIC_MODEL_MAP layer — /v1/messages now uses the
same model names as /v1/chat/completions (deepseek-v4-flash-free,
gpt-5.4-mini-no-login, deepseek/deepseek-v4-flash). This way users
send the original model name and it routes to the correct backend.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 00:42:21 +07:00
MythEclipseandClaude Fable 5 38d7a83fe9 feat: add AI proxy routes to Workers and Vercel entry points
- Add /v1/chat/completions, /v1/messages, /v1/models routes to
  src/worker.ts (Cloudflare Workers) and api/relay.ts (Vercel)
- Import handleChatCompletion, handleAnthropicMessages handlers
- Using the same backend routing as the standalone server

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 23:45:38 +07:00
MythEclipseandClaude Fable 5 3f96d8a6e7 fix: relay requests to / with x-relay-target instead of showing index
When a GET request hits / with an x-relay-target header, it should relay
the request — not display the index page. Fixed in all three entry points
(src/index.ts, api/relay.ts, src/worker.ts).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 21:59:25 +07:00
MythEclipseandClaude Fable 5 9dc32e8b10 fix: correct Vercel Bun runtime config and handler export format
Per Vercel docs (vercel.com/docs/functions/runtimes/bun):
- Use top-level "bunVersion": "1.x" in vercel.json (NOT functions block)
- Export default { async fetch(request) { ... } } — object with fetch method
  (not a bare default function)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 21:20:16 +07:00
MythEclipseandClaude Fable 5 591c1fa199 fix: add Vercel-compatible relay handler and fix vercel.json runtime
- Create api/relay.ts: Vercel serverless function handler that reuses
  relay logic from src/lib/relay-utils.ts and src/middleware/
- Export default fetch handler (no Bun.serve()) for Vercel Functions
- Fix vercel.json: use @vercel/node@5 runtime with proper routing via
  rewrites to catch all traffic to the relay handler
- Remove stale buildCommand/outputDirectory (Vercel handles function builds)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 21:17:21 +07:00