Another "Failed to ping server" issue #621

Closed
opened 2026-04-24 23:30:54 +02:00 by adam · 17 comments
Owner

Originally created by @azukaar on GitHub (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

Originally created by @azukaar on GitHub (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](https://github.com/advplyr/audiobookshelf-app/assets/7872597/f61b1f30-9cef-4fe1-9a0f-19e3c5d6f4a0) If I try to go to /ping directly in the browser, it works: ![image](https://github.com/advplyr/audiobookshelf-app/assets/7872597/e30048cc-752f-4ea1-995e-5aeffcab447b) And finally, I have noticed that when the mobile app requests the URL, the ABS server returns a 304 instead of a 200? ![image](https://github.com/advplyr/audiobookshelf-app/assets/7872597/5c6115b3-adcc-48c9-8c07-8b38fdf4d6ae) 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
adam added the bug label 2026-04-24 23:30:54 +02:00
adam closed this issue 2026-04-24 23:30:54 +02:00
Author
Owner

@advplyr commented on GitHub (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
        })
@advplyr commented on GitHub (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` ```js 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 }) ```
Author
Owner

@azukaar commented on GitHub (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 commented on GitHub (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
Author
Owner

@azukaar commented on GitHub (Jul 12, 2023):

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

@azukaar commented on GitHub (Jul 12, 2023): I have setup an isntance here if you want to give it a quick try @advplyr https://audiobookshelf.cosmos-cloud.io/
Author
Owner

@advplyr commented on GitHub (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.
@advplyr commented on GitHub (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. ```
Author
Owner

@azukaar commented on GitHub (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!

@azukaar commented on GitHub (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!
Author
Owner

@advplyr commented on GitHub (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

@advplyr commented on GitHub (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
Author
Owner

@azukaar commented on GitHub (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?)

@azukaar commented on GitHub (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?)
Author
Owner

@advplyr commented on GitHub (Jul 13, 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

@advplyr commented on GitHub (Jul 13, 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](https://capacitorjs.com/docs/apis/http) 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
Author
Owner

@azukaar commented on GitHub (Jul 13, 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

@azukaar commented on GitHub (Jul 13, 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
Author
Owner

@advplyr commented on GitHub (Jul 13, 2023):

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

@advplyr commented on GitHub (Jul 13, 2023): I'm actually not seeing the logs for CapacitorHttp in logcat. Did you update the server to `*` for testing?
Author
Owner

@advplyr commented on GitHub (Jul 13, 2023):

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

@advplyr commented on GitHub (Jul 13, 2023): Ah bummer, then it's probably not that simple. The requests will likely need to get changed manually then
Author
Owner

@advplyr commented on GitHub (Jul 13, 2023):

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

The artifact at the bottom of the page

@advplyr commented on GitHub (Jul 13, 2023): The APK is built https://github.com/advplyr/audiobookshelf-app/actions/runs/5536923526 The artifact at the bottom of the page
Author
Owner

@azukaar commented on GitHub (Jul 13, 2023):

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

@azukaar commented on GitHub (Jul 13, 2023): I reverted the CORS settings and tried with the new APK it does work now! Amazing reaction time :D
Author
Owner

@advplyr commented on GitHub (Jul 13, 2023):

Nice! Thanks for testing, this is an improvement.

@advplyr commented on GitHub (Jul 13, 2023): Nice! Thanks for testing, this is an improvement.
Author
Owner

@nonameboy007 commented on GitHub (Jul 28, 2023):

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

Edit: but ebooks does not be loaded..

@nonameboy007 commented on GitHub (Jul 28, 2023): no more "failed to ping server" problem with this apk . Thanks Edit: but ebooks does not be loaded..
Author
Owner

@advplyr commented on GitHub (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 commented on GitHub (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.
Author
Owner

@advplyr commented on GitHub (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

@advplyr commented on GitHub (Nov 18, 2023): Updated all requests EXCEPT the ereader in [v0.9.67-beta](https://github.com/advplyr/audiobookshelf-app/releases/tag/v0.9.67-beta) I'm not sure yet how the ereader will be handled
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf-app#621