From 1ceefd7231c545880fd652943ddb7e890d72dabd Mon Sep 17 00:00:00 2001
From: ngqile
Date: Wed, 2 Dec 2026 17:56:52 +0800
Subject: [PATCH] feat(pages): serve Custom HTML blocks from sealed frame
routes
Co-Authored-By: Claude Opus 5.5
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
---
.../changes/add-custom-html-block/tasks.md | 2 +-
.../app/lib/bodyLimit.pages.test.ts | 14 ++++
solvway-admin-portal/app/lib/bodyLimit.ts | 5 +-
.../app/lib/frameHtml.test.ts | 57 ++++++++++++++
solvway-admin-portal/app/lib/frameHtml.ts | 65 ++++++++++++++++
.../app/lib/frameRoutes.test.ts | 76 +++++++++++++++++++
solvway-admin-portal/app/lib/routeGuard.ts | 6 +-
.../p/[company]/[slug]/frame/[block]/route.ts | 15 ++++
.../pages/[id]/preview/frame/[block]/route.ts | 17 +++++
solvway-admin-portal/middleware.frame.test.ts | 30 ++++++++
solvway-admin-portal/middleware.ts | 4 +-
11 files changed, 286 insertions(+), 5 deletions(-)
create mode 100644 solvway-admin-portal/app/lib/bodyLimit.pages.test.ts
create mode 100644 solvway-admin-portal/app/lib/frameHtml.test.ts
create mode 100644 solvway-admin-portal/app/lib/frameHtml.ts
create mode 100644 solvway-admin-portal/app/lib/frameRoutes.test.ts
create mode 100644 solvway-admin-portal/app/p/[company]/[slug]/frame/[block]/route.ts
create mode 100644 solvway-admin-portal/app/pages/[id]/preview/frame/[block]/route.ts
create mode 100644 solvway-admin-portal/middleware.frame.test.ts
diff --git a/openspec/changes/add-custom-html-block/tasks.md b/openspec/changes/add-custom-html-block/tasks.md
index 30a1476..a43fdf8 100644
--- a/openspec/changes/add-custom-html-block/tasks.md
+++ b/openspec/changes/add-custom-html-block/tasks.md
@@ -14,7 +14,7 @@ Design: `design.md` and `docs/superpowers/specs/2026-12-02-custom-html-block-des
## 2. Portal
-- [ ] 2.1 Frame routes (public and preview) with the sandbox headers, the 404 rules and the height script.
+- [x] 2.1 Frame routes (public and preview) with the sandbox headers, the 404 rules and the height script.
- The middleware skips them; `routeGuard` admits the public frame path.
- Security code: read the whole diff.
- [ ] 2.2 `CmsBlocks`:
diff --git a/solvway-admin-portal/app/lib/bodyLimit.pages.test.ts b/solvway-admin-portal/app/lib/bodyLimit.pages.test.ts
new file mode 100644
index 0000000..415cd87
--- /dev/null
+++ b/solvway-admin-portal/app/lib/bodyLimit.pages.test.ts
@@ -0,0 +1,14 @@
+import { describe, it, expect } from "vitest";
+import { bodyLimit, DEFAULT_BODY_LIMIT, UPLOAD_BODY_LIMIT } from "./bodyLimit";
+
+// add-custom-html-block: a page save may carry several Custom HTML blocks of up to 200,000 characters each.
+describe("bodyLimit: page saves", () => {
+ it("gives page creates and updates the large limit", () => {
+ expect(bodyLimit("/api/pages")).toBe(UPLOAD_BODY_LIMIT);
+ expect(bodyLimit("/api/pages/12")).toBe(UPLOAD_BODY_LIMIT);
+ });
+
+ it("leaves other page-like paths on the default", () => {
+ for (const p of ["/api/pagesx", "/api/pages/12/other", "/api/companies/1/branding"]) expect(bodyLimit(p), p).toBe(DEFAULT_BODY_LIMIT);
+ });
+});
diff --git a/solvway-admin-portal/app/lib/bodyLimit.ts b/solvway-admin-portal/app/lib/bodyLimit.ts
index 783fa83..acbb4dc 100644
--- a/solvway-admin-portal/app/lib/bodyLimit.ts
+++ b/solvway-admin-portal/app/lib/bodyLimit.ts
@@ -2,12 +2,13 @@
// front of the portal caps it (a 2 MB POST reached the login route live). The middleware refuses an API write whose
// declared Content-Length exceeds its route's limit. Uploads (images, photos, documents, attachments, imports) get
// room for a 5 MB file sent as base64 JSON, as do email-template saves (free HTML, which may carry inline images);
-// everything else 1 MB.
+// everything else 1 MB. Landing-page saves get the large limit too (add-custom-html-block): a Custom HTML block holds
+// up to 200,000 characters.
export const DEFAULT_BODY_LIMIT = 1024 * 1024;
export const UPLOAD_BODY_LIMIT = 10 * 1024 * 1024;
-const UPLOAD_PATH = /\/(?:image|images|photos|upload|attachments|doc|invoice-header|import)(?:\/|$)|^\/api\/(?:fulfilment|email-templates)(?:\/|$)/;
+const UPLOAD_PATH = /\/(?:image|images|photos|upload|attachments|doc|invoice-header|import)(?:\/|$)|^\/api\/(?:fulfilment|email-templates)(?:\/|$)|^\/api\/pages(?:\/\d+)?$/;
export function bodyLimit(pathname: string): number {
return UPLOAD_PATH.test(pathname) ? UPLOAD_BODY_LIMIT : DEFAULT_BODY_LIMIT;
diff --git a/solvway-admin-portal/app/lib/frameHtml.test.ts b/solvway-admin-portal/app/lib/frameHtml.test.ts
new file mode 100644
index 0000000..def2282
--- /dev/null
+++ b/solvway-admin-portal/app/lib/frameHtml.test.ts
@@ -0,0 +1,57 @@
+import { describe, it, expect } from "vitest";
+import { FRAME_SANDBOX, frameDocument, frameResponse, nextFrameHeight, START_HEIGHT } from "./frameHtml";
+
+// add-custom-html-block: pasted HTML runs sealed, in its own document with a sandbox policy, and reports its height.
+describe("frameHtml", () => {
+ it("grants scripts and pop-ups only", () => {
+ expect(FRAME_SANDBOX.split(" ").sort()).toEqual(["allow-popups", "allow-popups-to-escape-sandbox", "allow-scripts"]);
+ });
+
+ it("adds the height script before
Hi