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

feat: allow loading config page from subdomain after sw registration #96

Merged
merged 12 commits into from
Mar 12, 2024

Conversation

SgtPooki
Copy link
Member

@SgtPooki SgtPooki commented Mar 8, 2024

Title

feat: pass through helia service worker assets & config page requests

Description

This fix allows you to reload the redirectPage (config in iframe) on any service worker registered in a subdomain by simply appending #/ipfs-sw-config to the URL.

It also passes through requests of the service worker source javascript to the server, which it didn't previously do.

NOTE: subdomains don't automatically refresh the service worker.. so we need some clever logic for checking for service worker assets, and then redirecting to /#/ipfs-sw-config again. We can handle this later? I will call this out in #31

Notes & open questions

  • Need to double check how this works on servers hosted on ipfs. Do we need some _redirects file magic for assets? I think it will work as is (because the assets DO exist on the server & in the content folder..), but need to test...
    • We do not need to do any special redirects handling. since the assets exist, and SW is passing them through, they will be served.
  • We can probably remove /config /#/ipfs-sw-config 302 from the _redirects file now?

This is built on top of #95 which is built on top of #89

Demo

2024-03-07.at.21.17.26.-.Orange.Unicorn.mp4

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

This comment was marked as outdated.

Base automatically changed from fix/refactor-for-cache-patch to refactor-for-cache March 8, 2024 19:07
Base automatically changed from refactor-for-cache to main March 9, 2024 00:31
@SgtPooki
Copy link
Member Author

We can create an easy reset for users by adding a #ipfs-sw-reset pathname flag that triggers the following code:

self.registration.unregister()
    .then(function() {
      return self.clients.matchAll();
    })
    .then(function(clients) {
      clients.forEach(client => client.navigate(client.url))
    });

It would be good to make sure this is in-place before changing the sw name.

public/_redirects Outdated Show resolved Hide resolved
@SgtPooki SgtPooki mentioned this pull request Mar 11, 2024
@SgtPooki
Copy link
Member Author

SgtPooki commented Mar 12, 2024

screenshot showing loading a subdomain, after adding a tiny little "log('test')" to sw.ts, when serving the assets with npm start:

image

See the last two lines:

Reloading the page resulted in the browser requesting the new service worker source, and updating it.

@SgtPooki SgtPooki merged commit 1201b22 into main Mar 12, 2024
19 checks passed
@SgtPooki SgtPooki deleted the feat/config-page-and-asset-handling branch March 12, 2024 00:22
2color added a commit that referenced this pull request Mar 12, 2024
* origin/main:
  feat: allow loading config page from subdomain after sw registration (#96)
  chore!: dist files optimizations (sw asset name changes) (#97)
  Update src/components/CidRenderer.tsx
  chore: remove in-page rendering
@lidel lidel mentioned this pull request Mar 15, 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.

2 participants