-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: first-hit handling renders redirect page correctly #163
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self review
const isSubdomainRender = isSubdomainGatewayRequest(window.location) | ||
const shouldRequestBeHandledByServiceWorker = isPathOrSubdomainRequest(window.location) && !isRequestToViewConfigPage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was being incorrectly set previously.
isPathOrSubdomainRequest
returns whether it is a path or subdomain request for ipfs/ipns contentisSubdomainRender
is now set to specifically represent if its a subdomain requestshouldRequestBeHandledByServiceWorker
is set to beisPathOrSubdomainRequest
& NOTisRequestToViewConfigPage
TODO: we should abstract this logic into a function we can test.
@@ -84,7 +84,7 @@ export default function RedirectPage (): JSX.Element { | |||
<h3 className="">{displayString}</h3> | |||
<ServiceWorkerReadyButton id="load-content" label='Load content' waitingLabel='Waiting for service worker registration...' onClick={() => { window.location.href = reloadUrl }} /> | |||
</div> | |||
<ConfigIframe /> | |||
{showConfigIframe && <ConfigIframe />} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
test.describe('first-hit ipfs-hosted', () => { | ||
/** | ||
* "ipfs-hosted" tests verify that when the _redirects is hit and redirects to the <root>?helia-sw=<path> that navigation is handled correctly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we don't have an ipfs server to test this with yet, and we don't need that complexity, we just test that the redirect path is handled properly.
eventually, we would test the full flow to guarantee ipfs hosting works e2e, which could be a good example to show users how to host this on ipfs themselves.
page: async ({ page, baseURL }, use) => { | ||
await page.goto(baseURL, { waitUntil: 'networkidle' }) | ||
await waitForServiceWorker(page) | ||
await setConfig({ | ||
page, | ||
config: { | ||
gateways: [process.env.KUBO_GATEWAY as string], | ||
routers: [process.env.KUBO_GATEWAY as string] | ||
} | ||
}) | ||
|
||
await use(page) | ||
} | ||
protocol: [baseURLProtocol, { scope: 'test' }] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we want rootDomain+protocol fixtures, but not to unnecessarily navigate or set config.
* to handle subdomain requests and origin isolation. | ||
*/ | ||
import httpProxy from 'http-proxy' | ||
/* eslint-disable no-console */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new native reverse-proxy using node:http..
Pretty simple, but I would have rather used a proxy library if one existed.. most are middleware or other more complex things that we don't need.
// eslint-disable-next-line no-console | ||
console.log('reverse proxy forwarding localhost traffic from port %d to %d', proxyPort, backendPort) | ||
proxyServer.listen(proxyPort, () => { | ||
console.log(`Proxy server listening on port ${proxyPort}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log(`Proxy server listening on port ${proxyPort}`) | |
console.log(`reverse proxy forwarding localhost traffic from port ${proxyPort} to ${backendPort}`) |
Title
fix: first-hit handling renders redirect page correctly
Description
Fixes an issue where first-hit handling was rendering an iframe when it shouldn't..
Summary of changes
first-hit
e2e testsNotes & open questions
Change checklist