Skip to content
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

problems with ample setup #1181

Open
djtulan opened this issue Nov 29, 2024 · 5 comments
Open

problems with ample setup #1181

djtulan opened this issue Nov 29, 2024 · 5 comments
Labels
6 - Ready for release Fix or feature is ready and will be included in the next release Bug

Comments

@djtulan
Copy link

djtulan commented Nov 29, 2024

Hi!

I'm not sure if I'm right at this place, but I would like to ask for help here.
I'm running nextcloud as a snap image also with the music plugin installed. Everything works fine!
At the same server, but as a different instance, I run an apache2 server configured to run ample & foam.

see https://github.com/Andrew-McGee/foam
see https://github.com/mitchray/ample

I can run foam without any issues, but I don't managed to run ample.
Since ample looks more developed, I would prefer it to foam.

But I always run into troubles with CORS.

Status
405
Method Not Allowed
VersionHTTP/1.1
Übertragen1,26 kB (0 B Größe)
Referrer Policystrict-origin-when-cross-origin
DNS-AuflösungSystem

Since I cannot modify the snap image so easily, I would like to ask if you know any solution?
Maybe I do something completely wrong?

@paulijar
Copy link
Collaborator

I believe that Foam makes the calls to the Ampache API from its back-end while Ample does them directly from its front-end. Because of this, Ample is affected by CORS restrictions but Foam is not.

That is, as-is, Ample works only if the server (Nextcloud Music in this case) is served from the same domain as Ample itself. I think that the Ample developer said somewhere on his GitHub that if anyone wants to use the app in different kind of configuration, then it's up to the user to solve the CORS issues. I'm not a subject matter expert on this, but probably it would mean modifying some HTTP headers of Ample. Maybe this could be done in the Apache configuration or then it would require modification on the Ample code.

@djtulan
Copy link
Author

djtulan commented Nov 29, 2024

As I understand, the Ampache server must set that special headers
see: https://github.com/mitchray/ample/wiki/Connecting-to-a-remote-Ampache-server-(CORS)

I don't know if this would be possible inside the Music Plugin Ampache code?
If so, I could try to set it in the plugin code.

paulijar added a commit that referenced this issue Nov 30, 2024
When a web app Ampache client such as Ample connects to the server from
another domain, the server must set certain headers to allow such access.
Also, the web app may do a "pre-flight" first by using the HTTP OPTIONS call
on the API endpoint, and the server must support this.

The Nextcloud server already contained support for such cases but a few steps
were needed to activate it on our Ampache endpoints:

- The endpoint functions need to be annotated with @cors. This is a sign for
  the CORSMiddleware in the server core to add the header
  'Access-Control-Allow-Origin'

- AmpacheController has to be inherited from ApiController and the allowed
  CORS headers need to be setup in the constructor. In addition to the
  default set of allowed headers, Ample requires 'X-Requested-With' as
  documented in
https://github.com/mitchray/ample/wiki/Connecting-to-a-remote-Ampache-server-(CORS)

- The base class ApiController provides the pre-fligth support with the
  function `preflightedCors` which needs to be mapped in routes.php.
  AmpacheMiddleware must not attempt to do any authentication checking on the
  pre-flight calls

The Nextcloud documentation for this can be found from
https://docs.nextcloud.com/server/30/developer_manual/digging_deeper/rest_apis.html

refs #1181
@paulijar
Copy link
Collaborator

paulijar commented Nov 30, 2024

I managed to enable the cross-origin calls to the Ampache API. It turned out that there was already good support utilities for this in the Nextcloud core and we just needed to hook to these. I just ended up using a way too much time trying to figure out, why the "pre-fligth" calls from Ample were working in some cases but not in others. In the end, I figured out it was my own middleware class messing things up by attempting to do authentication checking on these pre-flight calls (which don't actually contain any user or session details). 🤦

If you wish, you can probably monkey-patch your installation by applying the changes made in the commit linked above. It will still take some time before I'm ready to make the next official release of Music.

PS: It seems to me that Ample doesn't really work on the latest Chrome browser, it keeps hanging up and showing errors like "Maximum call stack size exceeded" in the console. This happens also with the official demo server of Ample, so I don't believe it to be related to anything done by NC Music. Ample works better on Firefox.

@paulijar paulijar added the Bug label Nov 30, 2024
@djtulan
Copy link
Author

djtulan commented Dec 1, 2024

I patched a view things in foam. also not that bad.
Thank you so much, I will give it a try soon.

@djtulan
Copy link
Author

djtulan commented Dec 1, 2024

Thank you very much Pauli! With your patch applied it works now.

@paulijar paulijar added the 6 - Ready for release Fix or feature is ready and will be included in the next release label Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6 - Ready for release Fix or feature is ready and will be included in the next release Bug
Projects
None yet
Development

No branches or pull requests

2 participants