diff --git a/public/_redirects b/public/_redirects index e31815fc..3b2133ec 100644 --- a/public/_redirects +++ b/public/_redirects @@ -1,2 +1 @@ -/config /#/config 302 /* /?helia-sw=/:splat 302 diff --git a/src/app.tsx b/src/app.tsx index f35c2259..a1c1775c 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -8,13 +8,19 @@ import RedirectPage from './redirectPage.tsx' function App (): JSX.Element { const { isConfigExpanded, setConfigExpanded } = useContext(ConfigContext) + const isRequestToViewConfigPage = isConfigPage(window.location.hash) + const isSubdomainRender = isPathOrSubdomainRequest(window.location) + + if (isRequestToViewConfigPage) { + if (isSubdomainRender) { + return + } - if (isConfigPage()) { setConfigExpanded(true) return } - if (isPathOrSubdomainRequest(window.location)) { + if (isSubdomainRender) { return () } diff --git a/src/components/config.tsx b/src/components/config.tsx index 9775863c..80a0ed50 100644 --- a/src/components/config.tsx +++ b/src/components/config.tsx @@ -45,7 +45,6 @@ export default (): JSX.Element | null => { return } // we get the iframe origin from a query parameter called 'origin', if this is loaded in an iframe - // TODO: why we need this origin here? where is targetOrigin used? const targetOrigin = decodeURIComponent(window.location.hash.split('@origin=')[1]) const config = await getConfig() trace('config-page: postMessage config to origin ', config, origin) diff --git a/src/context/config-context.tsx b/src/context/config-context.tsx index 81617063..a3237a1d 100644 --- a/src/context/config-context.tsx +++ b/src/context/config-context.tsx @@ -10,7 +10,7 @@ export const ConfigContext = createContext({ export const ConfigProvider = ({ children, expanded = isLoadedInIframe }: { children: JSX.Element[] | JSX.Element, expanded?: boolean }): JSX.Element => { const [isConfigExpanded, setConfigExpanded] = useState(expanded) - const isExplicitlyLoadedConfigPage = isConfigPage() + const isExplicitlyLoadedConfigPage = isConfigPage(window.location.hash) const setConfigExpandedWrapped = (value: boolean): void => { if (isLoadedInIframe || isExplicitlyLoadedConfigPage) { diff --git a/src/index.tsx b/src/index.tsx index fc14ec36..d353d095 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -17,7 +17,7 @@ const root = ReactDOMClient.createRoot(container) root.render( - + diff --git a/src/lib/is-config-page.ts b/src/lib/is-config-page.ts index a152e98d..1167292a 100644 --- a/src/lib/is-config-page.ts +++ b/src/lib/is-config-page.ts @@ -1,5 +1,4 @@ -export function isConfigPage (): boolean { - const isConfigPathname = window.location.pathname === '/config' - const isConfigHashPath = window.location.hash.startsWith('#/config') // needed for _redirects and IPFS hosted sw gateways - return isConfigPathname || isConfigHashPath +export function isConfigPage (hash: string): boolean { + const isConfigHashPath = hash.startsWith('#/ipfs-sw-config') // needed for _redirects and IPFS hosted sw gateways + return isConfigHashPath } diff --git a/src/redirectPage.tsx b/src/redirectPage.tsx index 4970a7ac..e669f299 100644 --- a/src/redirectPage.tsx +++ b/src/redirectPage.tsx @@ -4,13 +4,14 @@ import { ServiceWorkerContext } from './context/service-worker-context.tsx' import { HeliaServiceWorkerCommsChannel } from './lib/channel.ts' import { setConfig, type ConfigDb } from './lib/config-db.ts' import { getSubdomainParts } from './lib/get-subdomain-parts' +import { isConfigPage } from './lib/is-config-page' import { error, trace } from './lib/logger.ts' const ConfigIframe = (): JSX.Element => { const { parentDomain } = getSubdomainParts(window.location.href) const portString = window.location.port === '' ? '' : `:${window.location.port}` - const iframeSrc = `${window.location.protocol}//${parentDomain}${portString}#/config@origin=${encodeURIComponent(window.location.origin)}` + const iframeSrc = `${window.location.protocol}//${parentDomain}${portString}#/ipfs-sw-config@origin=${encodeURIComponent(window.location.origin)}` return (