Add backend reachability check method
This commit is contained in:
1 parent
45ff54d4d3
commit
60694258f2
1 file changed
+35
@@ -504,6 +504,41 @@ class NetworkService {
|
||||
return this.axiosInstance.get("/auth/users/superadmin");
|
||||
}
|
||||
|
||||
/**
|
||||
* ************************************
|
||||
* Checks if the backend server is reachable
|
||||
* ************************************
|
||||
*
|
||||
* @async
|
||||
* @returns {Promise<boolean>} True if backend is reachable, false otherwise
|
||||
*/
|
||||
async checkBackendReachability() {
|
||||
try {
|
||||
// Create a temporary instance that doesn't follow redirects and has a short timeout
|
||||
const tempInstance = axios.create({
|
||||
timeout: 5000,
|
||||
maxRedirects: 0,
|
||||
baseURL: this.axiosInstance.defaults.baseURL,
|
||||
});
|
||||
|
||||
// Make a simple GET request to the root endpoint
|
||||
await tempInstance.get('/', {
|
||||
headers: {
|
||||
Authorization: undefined // Prevent sending the auth token
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
// If we get a successful HTTP status or redirect, the backend is reachable
|
||||
if (error.response) {
|
||||
return true; // Server responded with any status code, so it's reachable
|
||||
}
|
||||
console.error("Backend connection failed:", error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ************************************
|
||||
* Get all users
|
||||
|
||||
Reference in new issue
Block a user