Skip to content

service-worker script wont load from non-root path #670

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

Closed
HenningCash opened this issue May 10, 2019 · 11 comments · Fixed by #834
Closed

service-worker script wont load from non-root path #670

HenningCash opened this issue May 10, 2019 · 11 comments · Fixed by #834
Labels
bug Something isn't working

Comments

@HenningCash
Copy link

HenningCash commented May 10, 2019

  • code-server version: 1.939-vsc1.33.1
  • OS Version: irrelevant

Description

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.

@HenningCash HenningCash added the bug Something isn't working label May 10, 2019
@geiseri
Copy link
Contributor

geiseri commented 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 the window.location to build something correctly.

@geiseri
Copy link
Contributor

geiseri commented 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
Copy link

jlewi commented 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
Copy link
Contributor

coadler commented May 24, 2019

cc @code-asher

@coadler
Copy link
Contributor

coadler commented May 24, 2019

@lucacasonato as well

@lucacasonato
Copy link
Contributor

I would add a --root flag and then make that the scope and the root path for all assets including the service worker.

@geiseri
Copy link
Contributor

geiseri commented 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 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.

@jlewi
Copy link

jlewi commented 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
Copy link
Author

@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.

@geiseri
Copy link
Contributor

geiseri commented 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.

@geiseri geiseri mentioned this issue May 28, 2019
@trobert2
Copy link

I opene #768 since I couldn't find this. Is it possible to add more tags here like reverse-proxy, ingress, kubernetes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants