Skip to content
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

Merged
merged 7 commits into from
Mar 29, 2024

Conversation

SgtPooki
Copy link
Member

@SgtPooki SgtPooki commented Mar 27, 2024

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

  • app.tsx now renders redirect page without iframe when appropriate.
  • fixes Minimal E2E tests  #134 with first-hit e2e tests
  • new reverse-proxy that's lighter and faster and one less dependent.
  • removes unnecessary ignoreHTTPSErrors option in playwright

Notes & open questions

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

@SgtPooki SgtPooki mentioned this pull request Mar 27, 2024
14 tasks
Copy link
Member Author

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self review

Comment on lines +12 to +13
const isSubdomainRender = isSubdomainGatewayRequest(window.location)
const shouldRequestBeHandledByServiceWorker = isPathOrSubdomainRequest(window.location) && !isRequestToViewConfigPage
Copy link
Member Author

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 content
  • isSubdomainRender is now set to specifically represent if its a subdomain request
  • shouldRequestBeHandledByServiceWorker is set to be isPathOrSubdomainRequest & NOT isRequestToViewConfigPage

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 />}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for path based requests in first-hit scenario, we don't want to show the iframe (because the request is on the rootDomain), but we do want to show the "waiting for service worker.." etc code.

ideally, we should show the config page outside of an iframe, but I'm open to ideas @lidel @2color


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.
Copy link
Member Author

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.

Comment on lines -17 to +16
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' }]
Copy link
Member Author

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 */
Copy link
Member Author

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}`)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log(`Proxy server listening on port ${proxyPort}`)
console.log(`reverse proxy forwarding localhost traffic from port ${proxyPort} to ${backendPort}`)

@SgtPooki SgtPooki merged commit a961662 into main Mar 29, 2024
20 checks passed
@SgtPooki SgtPooki deleted the test/e2e-first-hit-testing branch March 29, 2024 18:48
@lidel lidel mentioned this pull request Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Minimal E2E tests
1 participant