@catmint/adapter-vercel 0.0.0-prealpha.13 → 0.0.0-prealpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/function-gen.js +107 -45
- package/dist/function-gen.js.map +1 -1
- package/package.json +3 -3
package/dist/function-gen.js
CHANGED
|
@@ -279,6 +279,30 @@ ${headerPreset === "baseline"
|
|
|
279
279
|
const pathname = url.pathname;
|
|
280
280
|
const method = (req.method || "GET").toUpperCase();
|
|
281
281
|
|
|
282
|
+
// Establish the request-scoped AsyncLocalStorage context.
|
|
283
|
+
// This makes cookies(), headers(), getPlatform() etc. available
|
|
284
|
+
// to server functions, middleware, API endpoints, and RSC rendering.
|
|
285
|
+
const __webRequest = nodeReqToWebRequest(req);
|
|
286
|
+
const __store = ssrEntry.createRequestStore(__webRequest, { req, res });
|
|
287
|
+
await ssrEntry.runWithRequestContext(__store, async () => {
|
|
288
|
+
|
|
289
|
+
// Helper: flush pending Set-Cookie headers and accumulated response
|
|
290
|
+
// headers from the request store onto the Node.js response object.
|
|
291
|
+
function __flushPendingHeaders() {
|
|
292
|
+
// Apply accumulated response headers
|
|
293
|
+
__store.responseHeaders.forEach(function(value, key) {
|
|
294
|
+
res.setHeader(key, value);
|
|
295
|
+
});
|
|
296
|
+
// Apply pending Set-Cookie headers
|
|
297
|
+
var cookies = [];
|
|
298
|
+
__store.pendingCookies.forEach(function(pending) {
|
|
299
|
+
cookies.push(pending.serialized);
|
|
300
|
+
});
|
|
301
|
+
if (cookies.length > 0) {
|
|
302
|
+
res.setHeader("Set-Cookie", cookies);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
282
306
|
try {
|
|
283
307
|
// 1. Middleware execution — runs for all routes handled by this function.
|
|
284
308
|
// For RSC flight requests, run middleware against the TARGET page path
|
|
@@ -300,6 +324,7 @@ ${headerPreset === "baseline"
|
|
|
300
324
|
mwResult.shortCircuit.headers.forEach(function(value, key) {
|
|
301
325
|
res.setHeader(key, value);
|
|
302
326
|
});
|
|
327
|
+
__flushPendingHeaders();
|
|
303
328
|
var scBody = await mwResult.shortCircuit.text();
|
|
304
329
|
res.end(scBody);
|
|
305
330
|
return;
|
|
@@ -312,6 +337,7 @@ ${headerPreset === "baseline"
|
|
|
312
337
|
} catch (err) {
|
|
313
338
|
console.error("Middleware error:", err);
|
|
314
339
|
if (!res.headersSent) {
|
|
340
|
+
__flushPendingHeaders();
|
|
315
341
|
res.statusCode = 500;
|
|
316
342
|
res.end("Internal Server Error");
|
|
317
343
|
}
|
|
@@ -332,6 +358,7 @@ ${headerPreset === "baseline"
|
|
|
332
358
|
if (pathname.startsWith("/__catmint/fn/") && ssrEntry.handleServerFn) {
|
|
333
359
|
// Enforce POST method
|
|
334
360
|
if (method !== "POST") {
|
|
361
|
+
__flushPendingHeaders();
|
|
335
362
|
res.statusCode = 405;
|
|
336
363
|
res.setHeader("Content-Type", "application/json");
|
|
337
364
|
res.end(JSON.stringify({ error: "Method " + method + " not allowed, expected POST" }));
|
|
@@ -341,6 +368,7 @@ ${headerPreset === "baseline"
|
|
|
341
368
|
// Enforce Content-Type: application/json
|
|
342
369
|
const ct = (req.headers["content-type"] || "").toLowerCase();
|
|
343
370
|
if (ct && !ct.startsWith("application/json")) {
|
|
371
|
+
__flushPendingHeaders();
|
|
344
372
|
res.statusCode = 415;
|
|
345
373
|
res.setHeader("Content-Type", "application/json");
|
|
346
374
|
res.end(JSON.stringify({ error: "Unsupported Content-Type, expected application/json" }));
|
|
@@ -352,6 +380,7 @@ ${headerPreset === "baseline"
|
|
|
352
380
|
if (origin) {
|
|
353
381
|
const expectedHost = req.headers.host || "localhost";
|
|
354
382
|
if (origin !== \`https://\${expectedHost}\` && origin !== \`http://\${expectedHost}\`) {
|
|
383
|
+
__flushPendingHeaders();
|
|
355
384
|
res.statusCode = 403;
|
|
356
385
|
res.setHeader("Content-Type", "application/json");
|
|
357
386
|
res.end(JSON.stringify({ error: "Origin not allowed" }));
|
|
@@ -364,6 +393,7 @@ ${headerPreset === "baseline"
|
|
|
364
393
|
try {
|
|
365
394
|
parsed = body.length > 0 ? JSON.parse(body.toString("utf-8")) : undefined;
|
|
366
395
|
} catch {
|
|
396
|
+
__flushPendingHeaders();
|
|
367
397
|
res.statusCode = 400;
|
|
368
398
|
res.setHeader("Content-Type", "application/json");
|
|
369
399
|
res.end(JSON.stringify({ error: "Invalid JSON body" }));
|
|
@@ -375,6 +405,7 @@ ${headerPreset === "baseline"
|
|
|
375
405
|
// Check if the result IS a ClientSafeError (returned, not thrown)
|
|
376
406
|
if (__isClientSafeErrorLike(result.result)) {
|
|
377
407
|
applyMiddlewareHeaders();
|
|
408
|
+
__flushPendingHeaders();
|
|
378
409
|
res.statusCode = 200;
|
|
379
410
|
res.setHeader("Content-Type", "application/json");
|
|
380
411
|
res.end(JSON.stringify({
|
|
@@ -386,11 +417,13 @@ ${headerPreset === "baseline"
|
|
|
386
417
|
return;
|
|
387
418
|
}
|
|
388
419
|
applyMiddlewareHeaders();
|
|
420
|
+
__flushPendingHeaders();
|
|
389
421
|
res.statusCode = 200;
|
|
390
422
|
res.setHeader("Content-Type", "application/json");
|
|
391
423
|
res.end(JSON.stringify(result.result));
|
|
392
424
|
return;
|
|
393
425
|
}
|
|
426
|
+
__flushPendingHeaders();
|
|
394
427
|
res.statusCode = 404;
|
|
395
428
|
res.setHeader("Content-Type", "application/json");
|
|
396
429
|
res.end(JSON.stringify({ error: "Server function not found" }));
|
|
@@ -400,6 +433,7 @@ ${headerPreset === "baseline"
|
|
|
400
433
|
|
|
401
434
|
// RedirectError — send redirect envelope
|
|
402
435
|
if (__isRedirectErrorLike(err)) {
|
|
436
|
+
__flushPendingHeaders();
|
|
403
437
|
res.statusCode = 200;
|
|
404
438
|
res.setHeader("Content-Type", "application/json");
|
|
405
439
|
res.end(JSON.stringify({ __redirect: true, url: err.url, status: err.status }));
|
|
@@ -408,6 +442,7 @@ ${headerPreset === "baseline"
|
|
|
408
442
|
|
|
409
443
|
// ClientSafeError — developer opted in, expose to client
|
|
410
444
|
if (__isClientSafeErrorLike(err)) {
|
|
445
|
+
__flushPendingHeaders();
|
|
411
446
|
res.statusCode = err.statusCode;
|
|
412
447
|
res.setHeader("Content-Type", "application/json");
|
|
413
448
|
res.end(JSON.stringify({ error: err.message, data: err.data }));
|
|
@@ -417,6 +452,7 @@ ${headerPreset === "baseline"
|
|
|
417
452
|
// Default: sanitize — generic message with correlation hash
|
|
418
453
|
const ref = __errorRef(err);
|
|
419
454
|
console.error("[catmint] Error reference [ref: " + ref + "] — see above for full error");
|
|
455
|
+
__flushPendingHeaders();
|
|
420
456
|
res.statusCode = 500;
|
|
421
457
|
res.setHeader("Content-Type", "application/json");
|
|
422
458
|
res.end(JSON.stringify({ error: "Internal Server Error [ref: " + ref + "]" }));
|
|
@@ -428,6 +464,7 @@ ${headerPreset === "baseline"
|
|
|
428
464
|
if (pathname === "/__catmint/rsc" && method === "GET" && rscEntry.render) {
|
|
429
465
|
const targetPath = url.searchParams.get("path");
|
|
430
466
|
if (!targetPath) {
|
|
467
|
+
__flushPendingHeaders();
|
|
431
468
|
res.statusCode = 400;
|
|
432
469
|
res.setHeader("Content-Type", "application/json");
|
|
433
470
|
res.end(JSON.stringify({ error: "Missing ?path= parameter" }));
|
|
@@ -437,18 +474,21 @@ ${headerPreset === "baseline"
|
|
|
437
474
|
const rscResult = await rscEntry.render(targetPath);
|
|
438
475
|
if (rscResult) {
|
|
439
476
|
applyMiddlewareHeaders();
|
|
477
|
+
__flushPendingHeaders();
|
|
440
478
|
res.statusCode = 200;
|
|
441
479
|
res.setHeader("Content-Type", "text/x-component; charset=utf-8");
|
|
442
480
|
res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
|
443
481
|
await pipeWebStreamToResponse(rscResult.stream, res);
|
|
444
482
|
return;
|
|
445
483
|
}
|
|
484
|
+
__flushPendingHeaders();
|
|
446
485
|
res.statusCode = 404;
|
|
447
486
|
res.setHeader("Content-Type", "application/json");
|
|
448
487
|
res.end(JSON.stringify({ error: "No matching route" }));
|
|
449
488
|
} catch (err) {
|
|
450
489
|
console.error("RSC navigation error:", err);
|
|
451
490
|
if (!res.headersSent) {
|
|
491
|
+
__flushPendingHeaders();
|
|
452
492
|
res.statusCode = 500;
|
|
453
493
|
res.setHeader("Content-Type", "application/json");
|
|
454
494
|
res.end(JSON.stringify({ error: "RSC navigation error" }));
|
|
@@ -480,6 +520,7 @@ ${headerPreset === "baseline"
|
|
|
480
520
|
res.setHeader(key, value);
|
|
481
521
|
});
|
|
482
522
|
applyMiddlewareHeaders();
|
|
523
|
+
__flushPendingHeaders();
|
|
483
524
|
res.statusCode = result.response.status;
|
|
484
525
|
if (result.response.body) {
|
|
485
526
|
await pipeWebStreamToResponse(result.response.body, res);
|
|
@@ -489,6 +530,7 @@ ${headerPreset === "baseline"
|
|
|
489
530
|
return;
|
|
490
531
|
}
|
|
491
532
|
|
|
533
|
+
__flushPendingHeaders();
|
|
492
534
|
res.statusCode = 405;
|
|
493
535
|
res.setHeader("Content-Type", "text/plain");
|
|
494
536
|
res.end(\`Method \${method} not allowed\`);
|
|
@@ -512,6 +554,7 @@ ${headerPreset === "baseline"
|
|
|
512
554
|
if (prStats.isFile()) {
|
|
513
555
|
const content = await readFile(prFilePath);
|
|
514
556
|
applyMiddlewareHeaders();
|
|
557
|
+
__flushPendingHeaders();
|
|
515
558
|
res.statusCode = 200;
|
|
516
559
|
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
517
560
|
res.setHeader("Content-Length", content.byteLength);
|
|
@@ -530,6 +573,7 @@ ${headerPreset === "baseline"
|
|
|
530
573
|
if (rscResult) {
|
|
531
574
|
const htmlStream = await ssrEntry.renderToHtml(rscResult.stream, rscResult.headConfig);
|
|
532
575
|
applyMiddlewareHeaders();
|
|
576
|
+
__flushPendingHeaders();
|
|
533
577
|
res.statusCode = 200;
|
|
534
578
|
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
535
579
|
await pipeWebStreamToResponse(htmlStream, res);
|
|
@@ -538,11 +582,15 @@ ${headerPreset === "baseline"
|
|
|
538
582
|
}
|
|
539
583
|
|
|
540
584
|
// 7. Fallback 404
|
|
585
|
+
__flushPendingHeaders();
|
|
541
586
|
await sendStatusPage(res, 404, pathname);
|
|
542
587
|
} catch (err) {
|
|
543
588
|
console.error("Serverless function error:", err);
|
|
589
|
+
__flushPendingHeaders();
|
|
544
590
|
await sendStatusPage(res, 500, pathname);
|
|
545
591
|
}
|
|
592
|
+
|
|
593
|
+
}); // end runWithRequestContext
|
|
546
594
|
}
|
|
547
595
|
`;
|
|
548
596
|
}
|
|
@@ -553,7 +601,7 @@ function generateEdgeFunction(manifest, maxBodySize, headerPreset) {
|
|
|
553
601
|
return `// Auto-generated by @catmint/adapter-vercel (Edge runtime) — do not edit
|
|
554
602
|
import * as rscEntry from "./rsc/index.js";
|
|
555
603
|
import * as ssrEntry from "./ssr/index.js";
|
|
556
|
-
${hasMiddlewareProtected ? 'import { prerenderedPages } from "./prerendered.js";' : ""}
|
|
604
|
+
${hasMiddlewareProtected ? 'import { prerenderedPages } from "./prerendered.js";' : "var prerenderedPages = {};"}
|
|
557
605
|
${cacheAdapterSetup}
|
|
558
606
|
function __isClientSafeErrorLike(err) {
|
|
559
607
|
return err != null && typeof err === "object" && err.constructor && err.constructor.name === "ClientSafeError" && typeof err.statusCode === "number";
|
|
@@ -649,6 +697,18 @@ ${headerPreset === "baseline"
|
|
|
649
697
|
: ""} return new Response(body, { ...init, headers });
|
|
650
698
|
}
|
|
651
699
|
|
|
700
|
+
// Establish the request-scoped AsyncLocalStorage context.
|
|
701
|
+
// This makes cookies(), headers(), getPlatform() etc. available
|
|
702
|
+
// to server functions, middleware, API endpoints, and RSC rendering.
|
|
703
|
+
const __store = ssrEntry.createRequestStore(request, { request });
|
|
704
|
+
return ssrEntry.runWithRequestContext(__store, async () => {
|
|
705
|
+
|
|
706
|
+
// Helper: flush pending Set-Cookie headers and accumulated response
|
|
707
|
+
// headers from the request store onto the outgoing Response.
|
|
708
|
+
function __flushHeaders(response) {
|
|
709
|
+
return ssrEntry.applyPendingHeaders(response, __store);
|
|
710
|
+
}
|
|
711
|
+
|
|
652
712
|
try {
|
|
653
713
|
// 1. Middleware execution — runs for all routes handled by this function.
|
|
654
714
|
// For RSC flight requests, run middleware against the TARGET page path
|
|
@@ -665,7 +725,7 @@ ${headerPreset === "baseline"
|
|
|
665
725
|
|
|
666
726
|
if (mwResult.shortCircuit) {
|
|
667
727
|
// Middleware short-circuited — return its response directly
|
|
668
|
-
return mwResult.shortCircuit;
|
|
728
|
+
return __flushHeaders(mwResult.shortCircuit);
|
|
669
729
|
}
|
|
670
730
|
|
|
671
731
|
// Middleware passed — capture headers to merge into final response
|
|
@@ -674,7 +734,7 @@ ${headerPreset === "baseline"
|
|
|
674
734
|
}
|
|
675
735
|
} catch (err) {
|
|
676
736
|
console.error("Middleware error:", err);
|
|
677
|
-
return new Response("Internal Server Error", { status: 500 });
|
|
737
|
+
return __flushHeaders(new Response("Internal Server Error", { status: 500 }));
|
|
678
738
|
}
|
|
679
739
|
}
|
|
680
740
|
|
|
@@ -695,19 +755,19 @@ ${headerPreset === "baseline"
|
|
|
695
755
|
if (pathname.startsWith("/__catmint/fn/") && ssrEntry.handleServerFn) {
|
|
696
756
|
// Enforce POST method
|
|
697
757
|
if (method !== "POST") {
|
|
698
|
-
return secureResponse(
|
|
758
|
+
return __flushHeaders(secureResponse(
|
|
699
759
|
JSON.stringify({ error: "Method " + method + " not allowed, expected POST" }),
|
|
700
760
|
{ status: 405, headers: { "Content-Type": "application/json" } },
|
|
701
|
-
);
|
|
761
|
+
));
|
|
702
762
|
}
|
|
703
763
|
|
|
704
764
|
// Enforce Content-Type: application/json
|
|
705
765
|
const ct = (request.headers.get("content-type") || "").toLowerCase();
|
|
706
766
|
if (ct && !ct.startsWith("application/json")) {
|
|
707
|
-
return secureResponse(
|
|
767
|
+
return __flushHeaders(secureResponse(
|
|
708
768
|
JSON.stringify({ error: "Unsupported Content-Type, expected application/json" }),
|
|
709
769
|
{ status: 415, headers: { "Content-Type": "application/json" } },
|
|
710
|
-
);
|
|
770
|
+
));
|
|
711
771
|
}
|
|
712
772
|
|
|
713
773
|
// Validate Origin header
|
|
@@ -715,10 +775,10 @@ ${headerPreset === "baseline"
|
|
|
715
775
|
if (origin) {
|
|
716
776
|
const expectedOrigin = url.origin;
|
|
717
777
|
if (origin !== expectedOrigin) {
|
|
718
|
-
return secureResponse(
|
|
778
|
+
return __flushHeaders(secureResponse(
|
|
719
779
|
JSON.stringify({ error: "Origin not allowed" }),
|
|
720
780
|
{ status: 403, headers: { "Content-Type": "application/json" } },
|
|
721
|
-
);
|
|
781
|
+
));
|
|
722
782
|
}
|
|
723
783
|
}
|
|
724
784
|
|
|
@@ -726,33 +786,33 @@ ${headerPreset === "baseline"
|
|
|
726
786
|
const MAX_BODY_SIZE = ${maxBodySize};
|
|
727
787
|
const contentLength = parseInt(request.headers.get("content-length") || "0", 10);
|
|
728
788
|
if (contentLength > MAX_BODY_SIZE) {
|
|
729
|
-
return secureResponse(
|
|
789
|
+
return __flushHeaders(secureResponse(
|
|
730
790
|
JSON.stringify({ error: "Request body too large" }),
|
|
731
791
|
{ status: 413, headers: { "Content-Type": "application/json" } },
|
|
732
|
-
);
|
|
792
|
+
));
|
|
733
793
|
}
|
|
734
794
|
const bodyText = await request.text();
|
|
735
795
|
if (bodyText.length > MAX_BODY_SIZE) {
|
|
736
|
-
return secureResponse(
|
|
796
|
+
return __flushHeaders(secureResponse(
|
|
737
797
|
JSON.stringify({ error: "Request body too large" }),
|
|
738
798
|
{ status: 413, headers: { "Content-Type": "application/json" } },
|
|
739
|
-
);
|
|
799
|
+
));
|
|
740
800
|
}
|
|
741
801
|
let parsed;
|
|
742
802
|
try {
|
|
743
803
|
parsed = bodyText.length > 0 ? JSON.parse(bodyText) : undefined;
|
|
744
804
|
} catch {
|
|
745
|
-
return secureResponse(
|
|
805
|
+
return __flushHeaders(secureResponse(
|
|
746
806
|
JSON.stringify({ error: "Invalid JSON body" }),
|
|
747
807
|
{ status: 400, headers: { "Content-Type": "application/json" } },
|
|
748
|
-
);
|
|
808
|
+
));
|
|
749
809
|
}
|
|
750
810
|
try {
|
|
751
811
|
const result = await ssrEntry.handleServerFn(pathname, parsed);
|
|
752
812
|
if (result) {
|
|
753
813
|
// Check if the result IS a ClientSafeError (returned, not thrown)
|
|
754
814
|
if (__isClientSafeErrorLike(result.result)) {
|
|
755
|
-
return applyMiddlewareHeaders(secureResponse(JSON.stringify({
|
|
815
|
+
return __flushHeaders(applyMiddlewareHeaders(secureResponse(JSON.stringify({
|
|
756
816
|
__clientSafeError: true,
|
|
757
817
|
error: result.result.message,
|
|
758
818
|
statusCode: result.result.statusCode,
|
|
@@ -760,44 +820,44 @@ ${headerPreset === "baseline"
|
|
|
760
820
|
}), {
|
|
761
821
|
status: 200,
|
|
762
822
|
headers: { "Content-Type": "application/json" },
|
|
763
|
-
}));
|
|
823
|
+
})));
|
|
764
824
|
}
|
|
765
|
-
return applyMiddlewareHeaders(secureResponse(JSON.stringify(result.result), {
|
|
825
|
+
return __flushHeaders(applyMiddlewareHeaders(secureResponse(JSON.stringify(result.result), {
|
|
766
826
|
status: 200,
|
|
767
827
|
headers: { "Content-Type": "application/json" },
|
|
768
|
-
}));
|
|
828
|
+
})));
|
|
769
829
|
}
|
|
770
|
-
return secureResponse(
|
|
830
|
+
return __flushHeaders(secureResponse(
|
|
771
831
|
JSON.stringify({ error: "Server function not found" }),
|
|
772
832
|
{ status: 404, headers: { "Content-Type": "application/json" } },
|
|
773
|
-
);
|
|
833
|
+
));
|
|
774
834
|
} catch (err) {
|
|
775
835
|
// Always log full error server-side
|
|
776
836
|
console.error("[catmint] Server function error:", err);
|
|
777
837
|
|
|
778
838
|
// RedirectError — send redirect envelope
|
|
779
839
|
if (__isRedirectErrorLike(err)) {
|
|
780
|
-
return secureResponse(
|
|
840
|
+
return __flushHeaders(secureResponse(
|
|
781
841
|
JSON.stringify({ __redirect: true, url: err.url, status: err.status }),
|
|
782
842
|
{ status: 200, headers: { "Content-Type": "application/json" } },
|
|
783
|
-
);
|
|
843
|
+
));
|
|
784
844
|
}
|
|
785
845
|
|
|
786
846
|
// ClientSafeError — developer opted in, expose to client
|
|
787
847
|
if (__isClientSafeErrorLike(err)) {
|
|
788
|
-
return secureResponse(
|
|
848
|
+
return __flushHeaders(secureResponse(
|
|
789
849
|
JSON.stringify({ error: err.message, data: err.data }),
|
|
790
850
|
{ status: err.statusCode, headers: { "Content-Type": "application/json" } },
|
|
791
|
-
);
|
|
851
|
+
));
|
|
792
852
|
}
|
|
793
853
|
|
|
794
854
|
// Default: sanitize — generic message with correlation hash
|
|
795
855
|
const ref = await __errorRef(err);
|
|
796
856
|
console.error("[catmint] Error reference [ref: " + ref + "] — see above for full error");
|
|
797
|
-
return secureResponse(
|
|
857
|
+
return __flushHeaders(secureResponse(
|
|
798
858
|
JSON.stringify({ error: "Internal Server Error [ref: " + ref + "]" }),
|
|
799
859
|
{ status: 500, headers: { "Content-Type": "application/json" } },
|
|
800
|
-
);
|
|
860
|
+
));
|
|
801
861
|
}
|
|
802
862
|
}
|
|
803
863
|
|
|
@@ -805,32 +865,32 @@ ${headerPreset === "baseline"
|
|
|
805
865
|
if (pathname === "/__catmint/rsc" && method === "GET" && rscEntry.render) {
|
|
806
866
|
const targetPath = url.searchParams.get("path");
|
|
807
867
|
if (!targetPath) {
|
|
808
|
-
return secureResponse(
|
|
868
|
+
return __flushHeaders(secureResponse(
|
|
809
869
|
JSON.stringify({ error: "Missing ?path= parameter" }),
|
|
810
870
|
{ status: 400, headers: { "Content-Type": "application/json" } },
|
|
811
|
-
);
|
|
871
|
+
));
|
|
812
872
|
}
|
|
813
873
|
try {
|
|
814
874
|
const rscResult = await rscEntry.render(targetPath);
|
|
815
875
|
if (rscResult) {
|
|
816
|
-
return applyMiddlewareHeaders(secureResponse(rscResult.stream, {
|
|
876
|
+
return __flushHeaders(applyMiddlewareHeaders(secureResponse(rscResult.stream, {
|
|
817
877
|
status: 200,
|
|
818
878
|
headers: {
|
|
819
879
|
"Content-Type": "text/x-component; charset=utf-8",
|
|
820
880
|
"Cache-Control": "no-cache, no-store, must-revalidate",
|
|
821
881
|
},
|
|
822
|
-
}));
|
|
882
|
+
})));
|
|
823
883
|
}
|
|
824
|
-
return secureResponse(
|
|
884
|
+
return __flushHeaders(secureResponse(
|
|
825
885
|
JSON.stringify({ error: "No matching route" }),
|
|
826
886
|
{ status: 404, headers: { "Content-Type": "application/json" } },
|
|
827
|
-
);
|
|
887
|
+
));
|
|
828
888
|
} catch (err) {
|
|
829
889
|
console.error("RSC navigation error:", err);
|
|
830
|
-
return secureResponse(
|
|
890
|
+
return __flushHeaders(secureResponse(
|
|
831
891
|
JSON.stringify({ error: "RSC navigation error" }),
|
|
832
892
|
{ status: 500, headers: { "Content-Type": "application/json" } },
|
|
833
|
-
);
|
|
893
|
+
));
|
|
834
894
|
}
|
|
835
895
|
}
|
|
836
896
|
|
|
@@ -839,26 +899,26 @@ ${headerPreset === "baseline"
|
|
|
839
899
|
const result = await ssrEntry.handleEndpoint(pathname, method, request);
|
|
840
900
|
|
|
841
901
|
if (result) {
|
|
842
|
-
return applyMiddlewareHeaders(result.response);
|
|
902
|
+
return __flushHeaders(applyMiddlewareHeaders(result.response));
|
|
843
903
|
}
|
|
844
904
|
|
|
845
|
-
return secureResponse(\`Method \${method} not allowed\`, {
|
|
905
|
+
return __flushHeaders(secureResponse(\`Method \${method} not allowed\`, {
|
|
846
906
|
status: 405,
|
|
847
907
|
headers: { "Content-Type": "text/plain" },
|
|
848
|
-
});
|
|
908
|
+
}));
|
|
849
909
|
}
|
|
850
910
|
|
|
851
911
|
// 5. Pre-rendered pages WITH middleware: serve from inlined prerendered map.
|
|
852
|
-
if (method === "GET" &&
|
|
912
|
+
if (method === "GET" && Object.keys(prerenderedPages).length > 0) {
|
|
853
913
|
const prHtml = prerenderedPages[pathname];
|
|
854
914
|
if (prHtml) {
|
|
855
|
-
return applyMiddlewareHeaders(secureResponse(prHtml, {
|
|
915
|
+
return __flushHeaders(applyMiddlewareHeaders(secureResponse(prHtml, {
|
|
856
916
|
status: 200,
|
|
857
917
|
headers: {
|
|
858
918
|
"Content-Type": "text/html; charset=utf-8",
|
|
859
919
|
"Cache-Control": "public, max-age=0, must-revalidate",
|
|
860
920
|
},
|
|
861
|
-
}));
|
|
921
|
+
})));
|
|
862
922
|
}
|
|
863
923
|
}
|
|
864
924
|
|
|
@@ -867,19 +927,21 @@ ${headerPreset === "baseline"
|
|
|
867
927
|
const rscResult = await rscEntry.render(pathname);
|
|
868
928
|
if (rscResult) {
|
|
869
929
|
const htmlStream = await ssrEntry.renderToHtml(rscResult.stream, rscResult.headConfig);
|
|
870
|
-
return applyMiddlewareHeaders(secureResponse(htmlStream, {
|
|
930
|
+
return __flushHeaders(applyMiddlewareHeaders(secureResponse(htmlStream, {
|
|
871
931
|
status: 200,
|
|
872
932
|
headers: { "Content-Type": "text/html; charset=utf-8" },
|
|
873
|
-
}));
|
|
933
|
+
})));
|
|
874
934
|
}
|
|
875
935
|
}
|
|
876
936
|
|
|
877
937
|
// 7. Fallback 404
|
|
878
|
-
return await statusPageResponse(404, pathname);
|
|
938
|
+
return __flushHeaders(await statusPageResponse(404, pathname));
|
|
879
939
|
} catch (err) {
|
|
880
940
|
console.error("Edge function error:", err);
|
|
881
|
-
return await statusPageResponse(500, pathname);
|
|
941
|
+
return __flushHeaders(await statusPageResponse(500, pathname));
|
|
882
942
|
}
|
|
943
|
+
|
|
944
|
+
}); // end runWithRequestContext
|
|
883
945
|
}
|
|
884
946
|
`;
|
|
885
947
|
}
|
package/dist/function-gen.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function-gen.js","sourceRoot":"","sources":["../src/function-gen.ts"],"names":[],"mappings":"AAAA,kEAAkE;AA2BlE;;GAEG;AACH,SAAS,gBAAgB,CAAC,QAAqB;IAC7C,MAAM,WAAW,GA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgKxC,CAAC;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@catmint/adapter-vercel",
|
|
3
|
-
"version": "0.0.0-prealpha.
|
|
3
|
+
"version": "0.0.0-prealpha.15",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
|
-
"license": "
|
|
6
|
+
"license": "GPL-2.0",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"catmint": "0.0.0-prealpha.
|
|
17
|
+
"catmint": "0.0.0-prealpha.15"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"typescript": "^5.7.0"
|