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

Another "Failed to ping server" issue #781

Closed
azukaar opened this issue Jul 10, 2023 · 17 comments
Closed

Another "Failed to ping server" issue #781

azukaar opened this issue Jul 10, 2023 · 17 comments
Labels
bug Something isn't working

Comments

@azukaar
Copy link

azukaar commented Jul 10, 2023

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

  • Failed to ping server

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

@azukaar azukaar added the bug Something isn't working label Jul 10, 2023
@advplyr
Copy link
Owner

advplyr commented Jul 10, 2023

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

azukaar commented Jul 10, 2023

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

azukaar commented Jul 12, 2023

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

@advplyr
Copy link
Owner

advplyr commented Jul 12, 2023

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

azukaar commented Jul 12, 2023

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
Copy link
Owner

advplyr commented Jul 12, 2023

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

azukaar commented Jul 12, 2023

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 added a commit that referenced this issue Jul 12, 2023
@advplyr
Copy link
Owner

advplyr commented Jul 12, 2023

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

azukaar commented Jul 12, 2023

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
Copy link
Owner

advplyr commented Jul 12, 2023

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

@advplyr
Copy link
Owner

advplyr commented Jul 12, 2023

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

@advplyr
Copy link
Owner

advplyr commented Jul 12, 2023

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

The artifact at the bottom of the page

@azukaar
Copy link
Author

azukaar commented Jul 12, 2023

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

@advplyr
Copy link
Owner

advplyr commented Jul 12, 2023

Nice! Thanks for testing, this is an improvement.

@nonameboy007
Copy link

nonameboy007 commented Jul 28, 2023

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

Edit: but ebooks does not be loaded..

@advplyr
Copy link
Owner

advplyr commented Sep 19, 2023

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
Copy link
Owner

advplyr commented Nov 18, 2023

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

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

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

No branches or pull requests

3 participants