fix: hybrid default export to satisfy Vercel/Node and Bun/Workers contracts
- Export handler as default function for Vercel Serverless Function runtime. - Attach fetch method to default export object for Bun and Cloudflare Workers compatibility. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
ee989f72bf
commit
84e7d89a75
+10
-11
@@ -280,17 +280,13 @@ async function handleRelay(req: Request): Promise<Response> {
|
||||
// ─── Exported Vercel Function Handler ───────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Vercel Bun runtime handler.
|
||||
* Hybrid handler for Vercel/Node web-api and Bun/Workers runtimes.
|
||||
*
|
||||
* Vercel's Bun runtime expects a `default` export that is an object with
|
||||
* a `fetch` method — NOT a bare default function. This matches the
|
||||
* standard `Bun.serve()` handler shape.
|
||||
*
|
||||
* Handles routing, middleware, and relay logic — same semantics as the
|
||||
* standalone Bun.serve() server, minus WebSocket support.
|
||||
* Exports both:
|
||||
* 1. Default function: parsed by Vercel Node runtime.
|
||||
* 2. Default.fetch(): parsed by Cloudflare / Bun runtimes.
|
||||
*/
|
||||
export default {
|
||||
async fetch(req: Request): Promise<Response> {
|
||||
async function fetchHandler(req: Request): Promise<Response> {
|
||||
const url = new URL(req.url);
|
||||
|
||||
// Static routes — show index only when no relay target is requested
|
||||
@@ -401,5 +397,8 @@ export default {
|
||||
|
||||
// Generic HTTP relay
|
||||
return handleRelay(req);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default Object.assign(fetchHandler, {
|
||||
fetch: fetchHandler,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user