posit-dev / r-shinylive

https://posit-dev.github.io/r-shinylive/
Other
147 stars 15 forks source link

can service worker support IPFS? #60

Open LiNk-NY opened 4 months ago

LiNk-NY commented 4 months ago

Thank you for working on this exciting tech!

I was wondering if it is possible to host a shinylive app via IPFS https://ipfs.tech/ ?

In theory, it should work with a localhost connection?

I am only beginning to understand the infrastructure but in my testing, I get an error that says:

Shinylive uses a Service Worker, which requires either a connection to localhost, or a connection via https.

which seems to come from

// src/load-shinylive-sw.ts
var localhostNames = ["localhost", "127.0.0.1", "[::1]"];
if (window.location.protocol !== "https:" && !localhostNames.includes(window.location.hostname)) {
  const errorMessage = "Shinylive uses a Service Worker, which requires either a connection to localhost, or a connection via https.";
  document.body.innerText = errorMessage;
  throw Error(errorMessage);
}

The URL to the example app looks something like:

http://bafybeidqxcurjbnkahltgppzfwwcp6te2ncz426at3675vbebalxppe454.ipfs.localhost:8080/?filename=index.html

I'm using a native IPFS browser (Brave) connected to a local IPFS node.

Other experiments using Joe Cheng's example (fork here) seem to render only the text:

http://bafybeica5jbha66yt3mq34j4ndbxd74gg4idzfesblc5x3ncqnnvowdjzu.ipfs.localhost:8080/?filename=R-shinylive-demo.html

FWIW, the R-shinylive-demo.html was rendered with the #| standalone: true option.

Is this something that is possible?

Thank you!