0

I have done a lot of research, but there was no real success.

I'm looking for a way to check reachability/availability of hosts with angular? E.g. I want to check if the authentication backend is available? The only way I found so far is by using the HttpClient to open a connection and check if an error occurs?

Are there any other/better ways of accomplishing such a task?

Thanks in advance.

fiza khan
  • 1,280
  • 13
  • 24
user3066027
  • 317
  • 2
  • 4
  • 15
  • According to your words, I am considering availability check = HTTP Request status 200 or 404. There is no other way except HttpClient. The only connection bridge between frontend and backend is the HTTP communication – Debojyoti Sep 27 '18 at 07:09
  • Agree with Debojyoti, only way to check availability is trying to contact it. You may want to reduce the timeout on the XHR object to have a faster fail if the server is not responding (like `xhr.timeout = 1000;`) during your availability check. Also, make sure you are not checking a resource that has some HTTP caching applied -- that would give you false positives. – Greg Sep 27 '18 at 07:14
  • You can connect to the back end with a web socket. Is it a a better alternative? Probably not, but it really depends on your requirements. – Oram Sep 27 '18 at 07:22
  • The best option would be on "APP_INITIALIZATION" to run a ping to the server and see if you get a 200 success request or 503/504 (dont remember which one) as fail request and then having like a global variable "backendAvailable" true/false – Fyllekanin Sep 27 '18 at 07:48
  • i've got many connections to different backends (signalr, rest, some websockets) and i want to test, if those machines are available. But if there is no other way, i'm going to use a HttpClient test connections. thanks a lot! – user3066027 Sep 27 '18 at 08:42

0 Answers0