@cryptoschindler maybe Moritz can explain
I think you do this using the ICXProxy. https://github.com/dfinity/icx-proxy. How do you use it? Someone with more networking chops will have to explain.
itâs actually surprisingly easy and has been around for a while, i just never had the chance to try it!
thanks to @jplevyak & @ali.piccioni we have this.
-
sign up to firebase and create a new project (you can use other services like vercel as well but then youâll need to change the
makefile
). make sure you add your custom domain to the firebase hosting, in our casebtcflower.xyz
. -
clone the repo and change line 13 and 14 in the
makefile
from
read
$EDITOR service-worker/src/sw/http_request.ts
to
@read EDITOR; \
$$EDITOR service-worker/src/sw/http_request.ts
i had to do this so the makefile works in zsh
and bash
.
- next run
make setup
. when the command line prompts
update CANSTER_ID and MY_DOMAIN in agent-js/apps/sw-cert/src/sw/http_request.ts
enter the name of your favourite editor (vim
for example). this opens an editor where you need to change the CANISTER_ID
and MY_DOMAIN
to your respective values. save and close the editor.
-
next we are prompted to setup firebase. choose
Hosting: Configure files for Firebase Hosting and (optionally) set up GitHub Action deploys
and thenUse an existing project
. Now you should see and select the project you created in the first step. Keep the public directory at the defaultpublic
, chooseN
when asked about the single-page app and automatic builds and deploys. -
next you need to run
make build
, this will build the service worker, copy it to thepublic
directory and then deploy it with firebase. -
if you want to change something in the service worker just run
make build
to redeploy it
Now we basically have a GET
request to our btcflower.xyz
domain return the service worker to the client. After the service worker is installed in the clients browser, it will then communicate with the asset canister and validate the responses.
This is the same thing that happens when you access a canister through <canister_id>.ic0.app
, just that now the âboundary nodeâ (boundary nodes can do more than that) is under your control.
Hope that helps, enjoy your custom URLs!
thank you for sharing this! I got my domain connected, but got another error as below when I tried to access my custom domain
Failed to fetch response: TypeError: Failed to execute âfetchâ on âWorkerGlobalScopeâ: Illegal invocation
Any idea?
Are you using service-worker manually?
I had a similar problem and this is how I solved it. You need to upgrade service-worker code by passing fetch
to HttpAgent
Steps
- Find
const agent = new HttpAgent({ host: replicaUrl.toString() });
- And replace
const agent = new HttpAgent({
host: replicaUrl.toString(),
fetch: self.fetch.bind(self),
});
Hope this helps
@3cL1p5e7 works perfectly!!
thank you!
Just in case, I posted a PR
@frederikrothenberger Is it allowed to publish PR to dfinity/ic
? I didnât find any PR from community and it worries me
Hi @3cL1p5e7
Thank you for submitting the PR. Unfortunately, at the current time we do not accept external PRs for the main IC repo. But we are working on it and are planning to accept PRâs for some repos in the near future.
Regarding the actual service worker issue at hand: streaming support is definitely on our radar and we are aware that we need to support this use case in the future.
I will keep you updated regarding future developments of both accepting external contributions and changes to the service worker.
Best regards,
Frederik
Thank you so much for your reply, Frederik!
I suggest adding contribution guidelines stating as much: