Skip to content

Commit ec3fb3d

Browse files
committed
chore: warm up backend on startup
1 parent 2895793 commit ec3fb3d

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

ui/src/router/RouterView.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import DashBaseView from "../pages/dashboard/DashBaseView.vue";
1010
import HomeView from "../pages/HomeView.vue";
1111
import VerifyView from "../pages/verify/VerifyView.vue";
1212
import LoginView from "../pages/LoginView.vue";
13+
import {Health} from "../stores/health.js";
1314
1415
const routes = {
1516
'^/$': HomeView,
@@ -31,6 +32,7 @@ window.addEventListener('hashchange', () => {
3132
})
3233
3334
const currentView = computed(() => {
35+
Health.loadHealth().then(() => console.log("Backend is Healthy"))
3436
for (const path in routes) {
3537
if (new RegExp(path).test(currentPath.value)) {
3638
return routes[path]

ui/src/stores/health.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import axios from "axios";
2+
import {User} from "./user.js";
3+
4+
const VITE_KB_API_URL = import.meta.env.VITE_KB_API_URL
5+
6+
let user = User.loadCache();
7+
8+
export class Health {
9+
status
10+
11+
constructor(status) {
12+
this.status = status
13+
}
14+
15+
toJson() {
16+
return {
17+
'status': this.status
18+
}
19+
}
20+
21+
static fromJson(json) {
22+
let health = new Health()
23+
health.status = json['status']
24+
return health
25+
}
26+
27+
static async loadHealth() {
28+
// Used to warm up backend
29+
let r = await axios.get(`${VITE_KB_API_URL}/health`, {});
30+
31+
return Health.fromJson(r.data)
32+
}
33+
}

0 commit comments

Comments
 (0)