feat(web-app): add verification available connection to backend for the http client
This commit is contained in:
31
web-app/src/Services/HttpClient.ts
Normal file
31
web-app/src/Services/HttpClient.ts
Normal file
@@ -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<boolean> {
|
||||||
|
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<string> {
|
||||||
|
const response = await axios.get(`${BASE}${this._url}/${PING}`);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user