AI-native design editor. Open-source Figma alternative.
fix(cloud): serve the portal at the server's root (#1382)
Danila Poyarkovc7afac2183c4
diff --git a/packages/cloud/src/contract/portal.ts b/packages/cloud/src/contract/portal.tsindex 3bac61e09..8fd73c8a3 100644--- a/packages/cloud/src/contract/portal.ts+++ b/packages/cloud/src/contract/portal.ts@@ -1,10 +1,14 @@/*** The pages a Cloud server shows on its own address: sign-in, desktop sign-in approval, account* settings, and the administration console. Every runtime serves the portal's `cloud.html` at- * and below these paths; everything else reaches the API.+ * and below these paths, and at the server's root, which the portal sends on to its home;+ * everything else reaches the API.*/export const CLOUD_PORTAL_PAGE_ROOTS = ['/auth', '/cloud/device', '/account', '/admin'] as constexport function isCloudPortalPage(path: string): boolean {- return CLOUD_PORTAL_PAGE_ROOTS.some((root) => path === root || path.startsWith(`${root}/`))+ return (+ path === '/' ||+ CLOUD_PORTAL_PAGE_ROOTS.some((root) => path === root || path.startsWith(`${root}/`))+ )}diff --git a/packages/cloud/src/runtime/portal/server.ts b/packages/cloud/src/runtime/portal/server.tsindex 1188711d6..519a094cf 100644--- a/packages/cloud/src/runtime/portal/server.ts+++ b/packages/cloud/src/runtime/portal/server.ts@@ -39,7 +39,7 @@ export function createCloudServer(c.res = withIndexingPolicy(c.res, c.req.path, indexingPolicy)})if (portal) {- const pages = CLOUD_PORTAL_PAGE_ROOTS.flatMap((root) => [root, `${root}/*`])+ const pages = ['/', ...CLOUD_PORTAL_PAGE_ROOTS.flatMap((root) => [root, `${root}/*`])]server.on(['GET', 'HEAD'], pages, async (c) => {const page = await portal(PAGE_PATH, c.req.raw)return page ? c.body(page.body, 200, PAGE_HEADERS) : c.notFound()diff --git a/packages/cloud/tests/contract/portal.test.ts b/packages/cloud/tests/contract/portal.test.tsindex 27f5ecee0..8485dfa8f 100644--- a/packages/cloud/tests/contract/portal.test.ts+++ b/packages/cloud/tests/contract/portal.test.ts@@ -5,6 +5,7 @@ import { isCloudPortalPage } from '#cloud/contract'describe('Cloud portal pages', () => {test('cover sign-in, desktop approval, account, and console paths', () => {for (const path of [+ '/','/auth/sign-in','/cloud/device','/account',diff --git a/packages/cloud/tests/runtime/portal/server.test.ts b/packages/cloud/tests/runtime/portal/server.test.tsindex 7c293fe45..deeccfd91 100644--- a/packages/cloud/tests/runtime/portal/server.test.ts+++ b/packages/cloud/tests/runtime/portal/server.test.ts@@ -36,6 +36,7 @@ describe('Cloud server', () => {expect(page.headers.get('Content-Security-Policy')).toBe("frame-ancestors 'none'")expect(page.headers.get('Cache-Control')).toBe('no-cache')expect((await request('/account')).status).toBe(200)+ expect(await (await request('/')).text()).toContain('Portal')})test('leaves other paths and methods to the API', async () => {diff --git a/packages/docs/development/cloud.md b/packages/docs/development/cloud.mdindex c3836cc63..3ea16b356 100644--- a/packages/docs/development/cloud.md+++ b/packages/docs/development/cloud.md@@ -205,7 +205,7 @@ provider or a second sign-in step, it opens them in a browser and gets the perso`CLOUD_PORTAL_PAGE_ROOTS` in the contract lists the page paths, and every runtime serves`cloud.html` at and below them with `frame-ancestors 'none'`, so the approval page cannot be-framed. Both runtimes put the API behind the same Hono router, `createCloudServer` in+framed. The server's root gets the page too, and the portal sends it on to its home. Both runtimes put the API behind the same Hono router, `createCloudServer` in`src/runtime/portal`, which answers portal pages before the API and portal assets only where theAPI returns 404; Node reads the build named by `OPENPENCIL_CLOUD_PORTAL_DIR`, and the Worker readsits static assets. `bun run cloud:dev` keeps a