You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
service-worker script wont load from non-root path #670
We are running code-server behind a reverse proxy that uses paths instead of distinct domains. e.g. domain.com/ide/123456. The service-worker script introduced in #154 will try to load the script from domain.com/service-worker.js instead of domain.com/ide/123456/service-worker.js.
It should be sufficient (it's not) to remove the leading slash in navigator.serviceWorker.register("/service-worker.js");. So either navigator.serviceWorker.register("./service-worker.js"); or navigator.serviceWorker.register("service-worker.js");. But I haven't tested all scenarios, yet.
I was messing with this. The problem is going to be the scope also. I think navigator.serviceWorker.register('service-worker.js', {scope: './'}); will operate correctly. This way the service worker doesn't try to apply to other paths. Most of the time when I do a PWA with a service worker though I use an absolute path. I guess the other approach would be to use the window.location to build something correctly.
Ah, there are some consequences here with the stuff generated in the manifests, etc. I am not sure if they are using workbox, but that can take care of some madness, but I think it introduces other madness =)
The problem is you might not know what the mount point is when the server is started. I was trying to play games with location but then I got bogged down in CSP hell. That being said, maybe --root would work if there was a way to have the index.html as a template and its expanded from cli values.
@geiseri what issues did you encountered while working on this? The simple navigator.serviceWorker.register('service-worker.js', {scope: './'}) solution seems to work fine for me.
Paths from the manifest and links to assets inside the index.html shouldnt be a problem:
Relative paths inside the index.html are loaded relative to the document (you only have to ensure your URL ends in a slash which should be the case when using a reverse-proxy anyway)
Relative paths inside the manifest are loaded relative to the manifest-URL
I would love to see a solution without another CLI-option. The IDE shouldn't care about where it is mounted.
Actually, the register worked, it was the resulting CSP issues that popped up later. I got around some with making workbox local vs hosted on the CDN. I will PR that part while I work out a better solution on the CSP.
Activity
geiseri commentedon May 16, 2019
I was messing with this. The problem is going to be the scope also. I think
navigator.serviceWorker.register('service-worker.js', {scope: './'});will operate correctly. This way the service worker doesn't try to apply to other paths. Most of the time when I do a PWA with a service worker though I use an absolute path. I guess the other approach would be to use thewindow.locationto build something correctly.geiseri commentedon May 16, 2019
Ah, there are some consequences here with the stuff generated in the manifests, etc. I am not sure if they are using workbox, but that can take care of some madness, but I think it introduces other madness =)
jlewi commentedon May 24, 2019
Just want to chime in that I'm hitting this as well.
I'm trying to run coder on Kubernetes behind a reverse proxy. It would be great to get this fixed.
coadler commentedon May 24, 2019
cc @code-asher
coadler commentedon May 24, 2019
@lucacasonato as well
lucacasonato commentedon May 24, 2019
I would add a --root flag and then make that the scope and the root path for all assets including the service worker.
geiseri commentedon May 24, 2019
The problem is you might not know what the mount point is when the server is started. I was trying to play games with
locationbut then I got bogged down in CSP hell. That being said, maybe--rootwould work if there was a way to have theindex.htmlas a template and its expanded from cli values.jlewi commentedon May 27, 2019
A "--root" flag would work in our (Kubeflow)'s use case. We know the root path on which we will be serving it.
/cc @aronchick
HenningCash commentedon May 27, 2019
@geiseri what issues did you encountered while working on this? The simple
navigator.serviceWorker.register('service-worker.js', {scope: './'})solution seems to work fine for me.Paths from the manifest and links to assets inside the
index.htmlshouldnt be a problem:I would love to see a solution without another CLI-option. The IDE shouldn't care about where it is mounted.
geiseri commentedon May 28, 2019
Actually, the register worked, it was the resulting CSP issues that popped up later. I got around some with making workbox local vs hosted on the CDN. I will PR that part while I work out a better solution on the CSP.
trobert2 commentedon Jun 13, 2019
I opene #768 since I couldn't find this. Is it possible to add more tags here like reverse-proxy, ingress, kubernetes?