jcorporation / myMPD

myMPD is a standalone and mobile friendly web mpd client with a tiny footprint and advanced features.
https://jcorporation.github.io/myMPD/
GNU General Public License v3.0
419 stars 65 forks source link

SW/PWA doesn't work behind reverse proxy with path prefix #586

Closed Warr1024 closed 2 years ago

Warr1024 commented 2 years ago

myMPD version: 8.1.3

Describe the bug

When myMPD is running behind a reverse proxy with path prefix, (e.g. a /mympd/ that's stripped off by the proxy) then the service worker is not installed, and thus the PWA is not installable under Chrome.

Potential fix

I was able to make the app installable by just replacing the absolute paths hard-coded into client js with relative ones in line https://github.com/jcorporation/myMPD/blob/master/htdocs/js/mympd.js#L439, and I can submit a PR if this fix is acceptable.

To Reproduce

  1. Using an nginx reverse proxy that strips off the path prefix:
    location ~ ^.*/mympd/(?<suburi>.*) {
    proxy_pass http://127.0.0.1:8081/$suburi$is_args$args;
    # ...;
    }
  2. Open myMPD through the proxy in Chrome.

Expected behavior

  1. Observe that myMPD interface works as expected.
  2. Open webdev console and see no errors.
  3. See the "Install myMPD..." option (NOT just "add to home screen" or "create shortcut") option in Chrome menu.

Observed behavior

  1. Observe that myMPD interface works as expected.
  2. Open webdev console and see errors trying to install ServiceWorker.
  3. Do NOT see the "Install myMPD..." option (NOT just "add to home screen" or "create shortcut") option in Chrome menu.
  4. In Chrome webdev Application tab, see that app is not installable because it does not have a working ServiceWorker.

Server plattform (please complete the following information):

Client plattform (please complete the following information):

jcorporation commented 2 years ago

Thanks for the finding! The js should use only relative paths. Would be fixed for the next minor release.

jcorporation commented 2 years ago

Should be fixed in devel and in the v8.2.0 branch. Can you test?

Warr1024 commented 2 years ago

I couldn't get the v8.2.0 branch to load at all. I got an error calling dispose on an undefined thing, added a null guard to it, but then now get an error about trying to get classList from undefined that I can't trace. It seems like the js code doesn't work when initially loading the site, only if the page was already initialized.

jcorporation commented 2 years ago

Bug is also fixed in devel you can try this branch.

Warr1024 commented 2 years ago

Tested in f50473df and it works.

jcorporation commented 2 years ago

Greate!