From 0cc42fed64112ae2b2130a40e3442291b2c97881 Mon Sep 17 00:00:00 2001 From: Liren Tu Date: Sat, 28 Nov 2026 20:15:56 -0800 Subject: [PATCH 1/2] Add an embeddable office page at /embed --- apps/web/next.config.js | 21 +++++++++++++- apps/web/src/app/embed/page.tsx | 23 +++++++++++++++ apps/web/src/components/EmbedScene.tsx | 40 ++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 apps/web/src/app/embed/page.tsx create mode 100644 apps/web/src/components/EmbedScene.tsx diff --git a/apps/web/next.config.js b/apps/web/next.config.js index bc4a6dc7..a7e17ff1 100644 --- a/apps/web/next.config.js +++ b/apps/web/next.config.js @@ -1,3 +1,11 @@ +/** The sites that may frame `/embed` (localhost for their dev servers). */ +const EMBED_ANCESTORS = [ + "'self'", + 'https://starfish.sh', + 'https://www.starfish.sh', + 'http://localhost:*', +]; + /** @type {import('next').NextConfig} */ module.exports = { transpilePackages: ['@agentopia/lib', '@agentopia/viewer', '@agentopia/core'], @@ -21,7 +29,8 @@ module.exports = { headers: [{ key: 'Vary', value: 'Accept' }], })), { - source: '/(.*)', + // Every page but `/embed` refuses to be framed. + source: '/((?!embed$).*)', headers: [ { key: 'Content-Security-Policy', @@ -33,6 +42,16 @@ module.exports = { }, ], }, + { + // The office alone, for the sites allowed to show it in an iframe. + source: '/embed', + headers: [ + { + key: 'Content-Security-Policy', + value: `frame-ancestors ${EMBED_ANCESTORS.join(' ')};`, + }, + ], + }, ], images: { remotePatterns: [ diff --git a/apps/web/src/app/embed/page.tsx b/apps/web/src/app/embed/page.tsx new file mode 100644 index 00000000..e13ef07c --- /dev/null +++ b/apps/web/src/app/embed/page.tsx @@ -0,0 +1,23 @@ +import { type Metadata } from 'next'; + +import EmbedScene from '@/components/EmbedScene'; +import { TITLE } from '@/constants'; + +/** + * The office alone, for other sites to show in an iframe. It is the only page + * that may be framed (see `next.config.js`), and it stays out of search: the + * home page is the office's canonical home. + */ +export const metadata: Metadata = { + title: { absolute: TITLE }, + alternates: { canonical: '/' }, + robots: { index: false, follow: true }, +}; + +export default function Embed() { + return ( +
+ +
+ ); +} diff --git a/apps/web/src/components/EmbedScene.tsx b/apps/web/src/components/EmbedScene.tsx new file mode 100644 index 00000000..a42d6bea --- /dev/null +++ b/apps/web/src/components/EmbedScene.tsx @@ -0,0 +1,40 @@ +'use client'; + +import { useEffect, useRef } from 'react'; + +import { FULL_WEBSITE_URL } from '@/constants'; + +/** + * The office alone, for other sites to frame (`/embed`). The same demo as the + * home page, but its link under the slogan opens the website in a new tab + * rather than the get started card, since the card would be cramped in a + * frame. + */ +export default function EmbedScene() { + const host = useRef(null); + + useEffect(() => { + let dispose: (() => void) | null = null; + let cancelled = false; + void import('@agentopia/viewer/hero').then(({ mountHero }) => { + if (!cancelled && host.current) { + dispose = mountHero(host.current, { + link: { label: 'Get started', href: `${FULL_WEBSITE_URL}/#get-started` }, + }); + } + }); + return () => { + cancelled = true; + dispose?.(); + }; + }, []); + + return ( +
+ ); +} From c8fdb06d5565f00252c86d228037eed17b63b9e6 Mon Sep 17 00:00:00 2001 From: Liren Tu Date: Sat, 28 Nov 2026 20:23:16 -0800 Subject: [PATCH 2/2] Frame the home page instead of a separate /embed page --- apps/web/next.config.js | 14 ++++----- apps/web/src/app/embed/page.tsx | 23 --------------- apps/web/src/components/EmbedScene.tsx | 40 -------------------------- 3 files changed, 7 insertions(+), 70 deletions(-) delete mode 100644 apps/web/src/app/embed/page.tsx delete mode 100644 apps/web/src/components/EmbedScene.tsx diff --git a/apps/web/next.config.js b/apps/web/next.config.js index a7e17ff1..80b19a38 100644 --- a/apps/web/next.config.js +++ b/apps/web/next.config.js @@ -1,5 +1,5 @@ -/** The sites that may frame `/embed` (localhost for their dev servers). */ -const EMBED_ANCESTORS = [ +/** The sites that may frame the home page's office (localhost for their dev servers). */ +const FRAME_ANCESTORS = [ "'self'", 'https://starfish.sh', 'https://www.starfish.sh', @@ -29,8 +29,8 @@ module.exports = { headers: [{ key: 'Vary', value: 'Accept' }], })), { - // Every page but `/embed` refuses to be framed. - source: '/((?!embed$).*)', + // Every page but the home page refuses to be framed. + source: '/:path+', headers: [ { key: 'Content-Security-Policy', @@ -43,12 +43,12 @@ module.exports = { ], }, { - // The office alone, for the sites allowed to show it in an iframe. - source: '/embed', + // The home page is the office alone, so the sites allowed may show it in an iframe. + source: '/', headers: [ { key: 'Content-Security-Policy', - value: `frame-ancestors ${EMBED_ANCESTORS.join(' ')};`, + value: `frame-ancestors ${FRAME_ANCESTORS.join(' ')};`, }, ], }, diff --git a/apps/web/src/app/embed/page.tsx b/apps/web/src/app/embed/page.tsx deleted file mode 100644 index e13ef07c..00000000 --- a/apps/web/src/app/embed/page.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import { type Metadata } from 'next'; - -import EmbedScene from '@/components/EmbedScene'; -import { TITLE } from '@/constants'; - -/** - * The office alone, for other sites to show in an iframe. It is the only page - * that may be framed (see `next.config.js`), and it stays out of search: the - * home page is the office's canonical home. - */ -export const metadata: Metadata = { - title: { absolute: TITLE }, - alternates: { canonical: '/' }, - robots: { index: false, follow: true }, -}; - -export default function Embed() { - return ( -
- -
- ); -} diff --git a/apps/web/src/components/EmbedScene.tsx b/apps/web/src/components/EmbedScene.tsx deleted file mode 100644 index a42d6bea..00000000 --- a/apps/web/src/components/EmbedScene.tsx +++ /dev/null @@ -1,40 +0,0 @@ -'use client'; - -import { useEffect, useRef } from 'react'; - -import { FULL_WEBSITE_URL } from '@/constants'; - -/** - * The office alone, for other sites to frame (`/embed`). The same demo as the - * home page, but its link under the slogan opens the website in a new tab - * rather than the get started card, since the card would be cramped in a - * frame. - */ -export default function EmbedScene() { - const host = useRef(null); - - useEffect(() => { - let dispose: (() => void) | null = null; - let cancelled = false; - void import('@agentopia/viewer/hero').then(({ mountHero }) => { - if (!cancelled && host.current) { - dispose = mountHero(host.current, { - link: { label: 'Get started', href: `${FULL_WEBSITE_URL}/#get-started` }, - }); - } - }); - return () => { - cancelled = true; - dispose?.(); - }; - }, []); - - return ( -
- ); -}