Skip to content

Commit 556c533

Browse files
committed
refactor(adapter-cf): remove pretty/origin logic, drop GET JSON serving, use R2-only public access, and simplify build routes
1 parent 057c755 commit 556c533

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

  • packages/adapter-cloudflare/src/node

packages/adapter-cloudflare/src/node/bundle.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,15 @@ const WORKER_RUNTIME_JS = `
407407
return new Response('unauthorized', { status: 401 });
408408
}
409409
410+
const url = new URL(req.url);
410411
const body = await req.json().catch(() => ({}));
411412
const pretty = body.pretty ?? DEFAULT_PRETTY;
412-
const route = body.route;
413+
414+
// prefer query ?route=... but fall back to body.route for backwards-ish compat
415+
const route = url.searchParams.get('route') || body.route;
413416
414417
if (!route || typeof route !== 'string') {
415-
return new Response(JSON.stringify({ ok: false, error: 'Missing "route" in body' }), {
418+
return new Response(JSON.stringify({ ok: false, error: 'Missing "route" (use ?route=/path) in request' }), {
416419
status: 400,
417420
headers: { 'content-type': 'application/json' },
418421
});
@@ -454,7 +457,6 @@ const WORKER_RUNTIME_JS = `
454457
await writeManifest(env, next);
455458
456459
// per-route cache purge (worker cache) for all public paths of this route
457-
const url = new URL(req.url);
458460
const origin = url.origin;
459461
for (const p of publicPathsForRoute(route, env)) {
460462
await purgeCacheForPath(origin, p);
@@ -539,15 +541,16 @@ const WORKER_RUNTIME_JS = `
539541
return new Response(null, { status: 204 });
540542
}
541543
542-
if (req.method === 'POST' && url.pathname === '/__statikapi/build/route') {
543-
return handleBuildRoute(req, env);
544-
}
545-
546-
if (req.method === 'POST' && url.pathname === '/__statikapi/build') {
544+
if (req.method === 'POST' && url.pathname === '/build') {
545+
// /build?route=/posts/1 -> single route build
546+
if (url.searchParams.has('route')) {
547+
return handleBuildRoute(req, env);
548+
}
549+
// /build -> full build
547550
return handleBuild(req, env);
548551
}
549552
550-
if (req.method === 'GET' && url.pathname === '/__statikapi/manifest') {
553+
if (req.method === 'GET' && url.pathname === '/manifest') {
551554
const list = await readManifest(env);
552555
return new Response(JSON.stringify(list), { headers: { 'content-type': 'application/json' } });
553556
}

0 commit comments

Comments
 (0)