From d6e3a5c1e0b7db47d96477ce17e4c5f8b98fc038 Mon Sep 17 00:00:00 2001 From: fastium Date: Tue, 6 May 2025 16:22:23 +0200 Subject: [PATCH] feat(web-app): add verification available connection to backend for the http client --- web-app/src/Services/HttpClient.ts | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 web-app/src/Services/HttpClient.ts diff --git a/web-app/src/Services/HttpClient.ts b/web-app/src/Services/HttpClient.ts new file mode 100644 index 0000000..039ae40 --- /dev/null +++ b/web-app/src/Services/HttpClient.ts @@ -0,0 +1,31 @@ +import axios from "axios"; + +const BASE = "https://"; +const PING = "ping"; +const RACLETTE = "raclette"; +const PONG = "pong"; + +export class HttpClient { + private _url: string; + + constructor(url: string) { + this._url = url; + } + + async isConnected(): Promise { + var connected = false; + if (await this.ping()) { + connected = true; + console.log("Connected to backend!"); + } else { + connected = false; + console.log("Connection failed backend!"); + } + return connected; + } + + private async ping(): Promise { + const response = await axios.get(`${BASE}${this._url}/${PING}`); + return response.data; + } +}