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 ───────────────────────────────────────────
|
// ─── 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
|
* Exports both:
|
||||||
* a `fetch` method — NOT a bare default function. This matches the
|
* 1. Default function: parsed by Vercel Node runtime.
|
||||||
* standard `Bun.serve()` handler shape.
|
* 2. Default.fetch(): parsed by Cloudflare / Bun runtimes.
|
||||||
*
|
|
||||||
* Handles routing, middleware, and relay logic — same semantics as the
|
|
||||||
* standalone Bun.serve() server, minus WebSocket support.
|
|
||||||
*/
|
*/
|
||||||
export default {
|
async function fetchHandler(req: Request): Promise<Response> {
|
||||||
async fetch(req: Request): Promise<Response> {
|
|
||||||
const url = new URL(req.url);
|
const url = new URL(req.url);
|
||||||
|
|
||||||
// Static routes — show index only when no relay target is requested
|
// Static routes — show index only when no relay target is requested
|
||||||
@@ -401,5 +397,8 @@ export default {
|
|||||||
|
|
||||||
// Generic HTTP relay
|
// Generic HTTP relay
|
||||||
return handleRelay(req);
|
return handleRelay(req);
|
||||||
},
|
}
|
||||||
};
|
|
||||||
|
export default Object.assign(fetchHandler, {
|
||||||
|
fetch: fetchHandler,
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user