swingmusic icon indicating copy to clipboard operation
swingmusic copied to clipboard

[BUG] Running behind proxy issues

Open Raman236 opened this issue 9 months ago • 27 comments

Hi

first of all, amazing app! Perfect actually!

Some issues I found while running behind a proxy

  1. When clicking the arrows on the header, the app takes you to the previous webpage instead of being within the app.

Image

  1. The login button only works when you click on the text "Login"

  2. last.fm button doesnt work

Maybe there should be a parameter in the docker compose file to specify the website public URL? And use that to resolve the proper addresses

Raman236 avatar Mar 28 '25 13:03 Raman236

Hello @Raman236

Thank you for the compliment. It means a lot to me.

About #1 ... it's like that by design. There's no in-app back/forward navigation. The button mimic the browser's back/forward functionality

About #2 ... I have tried it on the latest version and it does not work as you have stated. The button is made of the HTML

About #3 ... it should be working. I've also tested on the latest version of Swing Music. There might be missing some documentation on how to go about it (I shall update the docs), but in the meantime here they are:

  1. Click the Connect button. This should open a new tab prompting to login to Last.fm and allow Swing Music to access your account. If this does not happen, please confirm that popups are not block for the Swing Music tab.
  2. In the new tab, log in to your Last.fm account and authorize Swing Music.
  3. Go back to Swing Music. The Connect button should now have the text Finish. Click it to finish the integration. After a successful integration, the button should now read Disconnect.

About the last one ... Maybe try using something like Nginx to do a reverse proxy to localhost?

Thank you.

cwilvx avatar Mar 30 '25 11:03 cwilvx

Hi.

I host over 20 open source apps on my server and synology. I dont have any issues with my proxy server. I run Authentik, meelo, outline, Ollama, openhand to name a few. No issues with my proxy.

Only have this issue with swingmusic. This must be a bug?

see, when i access directly using IP address:

Image Image

However, when I access through domain:

Image

Raman236 avatar Apr 23 '25 08:04 Raman236

Maybe there should be a parameter like it is in the environment file, where you can specify the URL

like External_URL: https://mymusic.domain.com

I know some apps specify local and external URL access

Raman236 avatar Apr 23 '25 08:04 Raman236

i have specifically this error:

Mixed Content: The page at 'https://MYDOMAIN.TLD/#/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://MYDOMAIN.TLD//nothome/?limit=4'. This request has been blocked; the content must be served over HTTPS.

and then for LastFM: index.96f2d32a.js:29 Mixed Content: The page at 'https://MYDOMAIN.TLD/#/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://ws.audioscrobbler.com/2.0/?format=json&method=auth.getToken&api_key=......'. This request has been blocked; the content must be served over HTTPS.

The issue is, that Swing Music is fetching over HTTP i suppose...

maskalix avatar Apr 25 '25 18:04 maskalix

Same issues here. Last.fm and the home site work just fine when I access the page via IP-Adress locally. But when I access it via a reverse proxy, I have the same issues @Raman236 mentioned.

Shousokon avatar May 09 '25 20:05 Shousokon

Hi @Raman236 @Shousokon @maskalix

I think this problem is related to how the base url used to http requests was being resolved and used in the webclient (using a full url). I have refactored that to use relative urls as the webclient is served by the swing music server.

I have build a testing docker image with the new change (v2.0.5.beta1) which you can find below:

https://github.com/orgs/swingmx/packages/container/swingmusic/412555917?tag=v2.0.5.beta1

Can you please try pulling this version and running it and let me know if the issue has been fixed? I would really appreciate it.

Thank you ❤

cwilvx avatar May 10 '25 15:05 cwilvx

Hey @cwilvx

for me this sadly did not fix the issue.

Home page when accessed via IP:Port adress

Home page when accessed via reverse proxy domain

Edit: Also the button to link last.fm only works when accessed via IP-adress

Shousokon avatar May 10 '25 17:05 Shousokon

Hi I am happy this is finally being looked at. I moved to meelo music server since no one was taking this seriously. I thought maybe its just my poor technical knowledge, i'm just a layman anyhow.

I appreciate @cwilvx you taking the time to look into this. I personally raelly loved SwingMusic! its fantastic. but because running behind proxy had issues, i dropped it.

I have checked out the v2.0.5.beta1. Sadly as well, no resolution. same results as @Shousokon

is there something we can give you like some logs or something that can help?

Raman236 avatar May 11 '25 00:05 Raman236

my screenshots with IP: 192.168.1.21:7058

Image

behind proxy:

Image

Raman236 avatar May 11 '25 00:05 Raman236

@Raman236 @maskalix @Shousokon

I'm unable to one-shot-kill this problem mostly because I'm unable to reproduce on my server. If you could provide your Nginx configurations (and/or other related configs) I think that would be of great help.

Are you manually passing the --host 0.0.0.0 parameter to swingmusic? The latest builds default to that so it should not be a problem anyway.

cwilvx avatar May 11 '25 10:05 cwilvx

@cwilvx

This is how I host Swing Music:

Docker

I'm running Swing Music as a docker container on my Synology NAS, managed with Portainer. This is my config:

version: "3.9"
services:
  swingmusic:
    container_name: Swing-Music
    image: ghcr.io/swingmx/swingmusic:v2.0.5.beta1
    mem_limit: 6g
    cpu_shares: 768
    security_opt:
      - no-new-privileges:true
    restart: on-failure:5
    ports:
      - 1970:1970
    volumes:
      - /volume1/Media/Musik:/music:ro
      - /volume1/docker/swingmusic/config:/config:rw

Other than that I do not have any other config changes to the docker container itself.

Reverse proxy

I run the reverse proxy directly within the synology control panel

I use this method also for other docker containers but swing music is the only one with those issues.

Logs

Docker Container

After startup

Swing Music v2.0.5.beta1 
Server running on:
http://0.0.0.0:1970
http://127.0.0.1:1970
http://172.23.0.2:1970
Data folder: /config/swingmusic

Browser Console

Mixed Content: The page at 'https://redacted.domain.com/#/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://redacted.domain.com/nothome/?limit=8'. This request has been blocked; the content must be served over HTTPS.
Error: TypeError: Cannot read properties of undefined (reading 'data')
    at qe (index.7685dc52.js:29:11954)
    at async Ehe (index.7685dc52.js:50:9234)
    at async Proxy.i (index.7685dc52.js:50:9663)
    at async index.7685dc52.js:84:53905
TypeError: Cannot read properties of undefined (reading 'entries')
    at Proxy.i (index.7685dc52.js:50:9711)
    at async index.7685dc52.js:84:53905

I hope this helps, if there is anything else I could test, just let me know (also if there is another place of useful logs).

Shousokon avatar May 11 '25 10:05 Shousokon

I tried a few things and found a fix for this: When adding the following to the <head> tag of the site, the home page loads the same with and without reverse proxy

<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">

Image

I tried adding this as reverse proxy header as well but this somehow did not work, so I guess you need to add this to the code (I'm not a programmer myself so I might be wrong here).

Shousokon avatar May 11 '25 16:05 Shousokon

I've released a new v2.0.6.beta1 which upgrades internal requests as suggested by @Shousokon.

https://github.com/orgs/swingmx/packages/container/swingmusic/413962719?tag=v2.0.6.beta1

Please try the new version and let me know if that worked.

cwilvx avatar May 12 '25 21:05 cwilvx

Thanks @cwilvx Swing Music works without any issues now when hosted with a reverse proxy. However (and I didn't thought of this before), when accessed via the IP-adress, the site doesnt work now, because the new head forces to use ssl.

Access Swing Music via reverse proxy

Image

Access Swing Music via IP-adress

Image

Maybe it would be useful to declare a docker environment variable ("External_URL = XXX" or something similar to this) when deploying. @Raman236 also suggested this before. I've seen this on other docker projects as well. Or if "http" is hard coded into the app, it might help using dynamic links instead?

I'm kinda out of ideas here myself, since I'm not really experienced in programming.

Shousokon avatar May 12 '25 22:05 Shousokon

Hi @Shousokon

Thanks for confirming that the new build works on Reverse proxy. I only wanted to confirm that specific side so breaking the HTTP side was expected.

With HTTPS working, I can now go ahead and make fixes to support both. I'll post a comment here when I have a beta2 to test the final fix. I'm trying to avoid using the external url setting, but I'll see if it will come down to that.

Thanks again ❤

cwilvx avatar May 13 '25 10:05 cwilvx

Sounds good @cwilvx I really like Swing Music and I appreciate that you look into this 🙏. Thanks a lot!

Shousokon avatar May 13 '25 11:05 Shousokon

Hello @Shousokon

Here's the new build which should work on both HTTP and HTTPS. Please let know if this works.

https://github.com/orgs/swingmx/packages/container/swingmusic/414795938?tag=v2.0.6.beta2

cwilvx avatar May 13 '25 19:05 cwilvx

Hey @cwilvx

thanks a lot! The home page + last.fm connection now both work via HTTP and HTTPS.

I tested a few more things in the web app but couldn't spot any issues with v2.0.6.beta2 🥳

Shousokon avatar May 13 '25 20:05 Shousokon

Awesome! @cwilvx

So I have tested this out and it works via reverse proxy, https.

I am not able to test locally as I'm not at home now.

There are other stuff like the home page doesn't display artists, and things compared to the screenshots previously posted. I'm hoping that's because this is was just a beta test and would work normally in production? 😅

Raman236 avatar May 13 '25 21:05 Raman236

@Raman236 I just looked over my home page again and compared it to older screenshots but I can't really spot any missing sections on my end.

I did however had to fully refresh the site once when I updated from one beta to a newer beta version by pressing Ctrl+F5. This loaded the whole site content then. Ig some browser caching was involved here.

Shousokon avatar May 13 '25 21:05 Shousokon

Hello @Shousokon

Here's the new build which should work on both HTTP and HTTPS. Please let know if this works.

https://github.com/orgs/swingmx/packages/container/swingmusic/414795938?tag=v2.0.6.beta2

Now i successfully logged in with LastFM... But doesn't seem to scrobble at all...

maskalix avatar May 13 '25 22:05 maskalix

@maskalix I also tested last.fm and for me it works

Shousokon avatar May 13 '25 23:05 Shousokon

Thank you guys for testing this. I really appreciate it.

The missing homepage items are probably due to the low usage. Once you start listening to more music, the sections will be filled as they are curated based on your listening activity. @Raman236

cwilvx avatar May 13 '25 23:05 cwilvx

@maskalix

I'm not sure why LastFM scrobble is not working for your setup. Do you have any error or logs, or anything that might help diagnose the problem?

You can look for errors on the web console after a track ends or the terminal. Let me know if you see any kind of error.

cwilvx avatar May 13 '25 23:05 cwilvx

Image

Image

Image

duendeakrata avatar Jun 04 '25 10:06 duendeakrata

Hello @Shousokon Here's the new build which should work on both HTTP and HTTPS. Please let know if this works. https://github.com/orgs/swingmx/packages/container/swingmusic/414795938?tag=v2.0.6.beta2

Now i successfully logged in with LastFM... But doesn't seem to scrobble at all...

I have the same issue with lastfm, i have connect to my account from swingmusic but nothing scrobble, in each song it calls: /logger/track/log

with this payload: {"trackhash":"b0b521677dd5c1b6","duration":29,"source":"al:e2ea0c70c11d36d5","timestamp":1749125386}

and the response: msg : "recorded"

but nothing happens in my lastfm account

edit:

this is the docker logs:

[12:18:55] [ERROR] LASTFM: scrobble error{'message': 'Invalid session key - Please re-authenticate', 'error': 9} (lastfm.py:110)
[12:18:55] [ERROR] LAST.FM: Invalid session key (lastfm.py:113)

Exception in thread Thread-59 (scrobble):
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/threading.py", line 1045, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.11/threading.py", line 982, in run
    self._target(*self._args, **self._kwargs)
  File "/app/swingmusic/swingmusic/plugins/lastfm.py", line 84, in scrobble
    success = self.post_scrobble_data({**data})
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/swingmusic/swingmusic/plugins/lastfm.py", line 115, in post_scrobble_data
    self.config.lastfmSessionKeys.pop(str(get_current_userid()))
KeyError: '1'

nesticle8bit avatar Jun 05 '25 12:06 nesticle8bit

Hello @nesticle8bit

From the error you have shared, it seems like the scrobbles are being rejected by Last.fm due to an invalid session key. Please try reconnecting your Last.fm account.

ps: the KeyError is happening because of a missing session key for your Swing Music user. It should not happen, and will be handled properly in future releases.

cwilvx avatar Jun 06 '25 14:06 cwilvx