advplyr / audiobookshelf-app

Mobile application for Audiobookshelf
https://audiobookshelf.org
GNU General Public License v3.0
1.3k stars 173 forks source link

Another "Failed to ping server" issue #781

Closed azukaar closed 1 year ago

azukaar commented 1 year ago

Hello, I am the dev of Cosmos, and using it as a reverse proxy seems to not work with the ABS app and I cannot see why.

Steps to reproduce

  1. Create ABS behind Cosmos as the Reverse proxy
  2. Create admin account
  3. Login to https://yourserver.com/

Actual behavior

More info

First of all I have spent significant amount of time searching this and here's what I can gather:

Despite of the app not working, the server receives the ping without any issues.

image

If I try to go to /ping directly in the browser, it works:

image

And finally, I have noticed that when the mobile app requests the URL, the ABS server returns a 304 instead of a 200?

image

Any pointer as to what needs to be done for it to work would be appreciated as there are not additional hints / errors / etc... anywhere

advplyr commented 1 year ago

Hey, are you using iOS or android? Where did you pull that log from with the response from the server on the mobile app?

The ping is happening like this in the mobile app. I've been meaning to try to provide a better error response here but if you are using android and can see the logcat you may be able to see that error getting logged in console.error

return this.$axios
        .$get(`${address}/ping`, options)
        .then((data) => data.success)
        .catch((error) => {
          console.error('Server check failed', error)
          this.error = 'Failed to ping server'
          return false
        })
azukaar commented 1 year ago

Hey thanks for you answer, I am indeed using Android I tried doing

adb shell
logcat | grep com.audiobookshelf.app

But I do not seem to be getting the logs from the app? (Sorry if I misunderstood you on something)

If I remove the GREP, the only thing I see that happens on click is

1805 tf_lite_classifier.cc:383] Event stream classified as kNone

But I doubt this is related

azukaar commented 1 year ago

I have setup an isntance here if you want to give it a quick try @advplyr https://audiobookshelf.cosmos-cloud.io/

advplyr commented 1 year ago

I tested on Android Pixel 6

Msg: Access to XMLHttpRequest at 'https://audiobookshelf.cosmos-cloud.io/ping' from origin 'http://localhost' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains multiple values 'audiobookshelf.cosmos-cloud.io, *', but only one is allowed.
azukaar commented 1 year ago

OK I added a patch to prevent the origin server's headers to reach the client but I still see "failed to ping the server" Would you mind giving it another look when you can? Thanks!

advplyr commented 1 year ago
Access to XMLHttpRequest at 'https://audiobookshelf.cosmos-cloud.io/ping' from origin 'http://localhost' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains the invalid value 'audiobookshelf.cosmos-cloud.io'

I think the origin will need to be * because the mobile client (origin in this case) won't be your server address

azukaar commented 1 year ago

I think you should disable that check from the mobile client no? It doesn't make sense to check the CORS header from mobile if you have no origin URL? I shouldn't set the CORS header to always be * that would defy the point of CORS to prevent other websites from requesting that URL

EDIT: I think there might be more to this as googling this issue shows only Flutter Web response? Nothing about mobile. What library are you using?

EDIT2: Are you using Flutter Web with a webview? I think that's the issue, because Flutter Mobile would not test for CORS.

(PS: just out of curiosity why not use Flutter directly?)

advplyr commented 1 year ago

We had discussed this before about changing the web view http requests to native http requests. That was a bit over a year ago and I think this is a new addition to the core capacitor plugins.

This is pretty great because it intercepts the outgoing web view requests and changes them to native requests without me needing to manually update every request. This worked in my testing to ping your server.

An APK gets built for each commit if you want to test that when it is done. Hopefully this also works for all the static content. #254 might be able to get supported easier now

azukaar commented 1 year ago

Nice one!! I will test right away By the way if you tested on the server, I had CORS set to *, to do some testing on my end. I just reverted it to the default

advplyr commented 1 year ago

I'm actually not seeing the logs for CapacitorHttp in logcat. Did you update the server to * for testing?

advplyr commented 1 year ago

Ah bummer, then it's probably not that simple. The requests will likely need to get changed manually then

advplyr commented 1 year ago

The APK is built https://github.com/advplyr/audiobookshelf-app/actions/runs/5536923526

The artifact at the bottom of the page

azukaar commented 1 year ago

I reverted the CORS settings and tried with the new APK it does work now! Amazing reaction time :D

advplyr commented 1 year ago

Nice! Thanks for testing, this is an improvement.

nonameboy007 commented 1 year ago

no more "failed to ping server" problem with this apk . Thanks

Edit: but ebooks does not be loaded..

advplyr commented 1 year ago

This is partially updated in 0.9.66-beta. I couldn't fully implement this because of a limitation in that plugin that didn't allow for loading ebooks so you may still get cover loading issues. You shouldn't have issues logging in anymore though so let me know.

advplyr commented 12 months ago

Updated all requests EXCEPT the ereader in v0.9.67-beta

I'm not sure yet how the ereader will be handled