Skip to content

Commit 6b63cbd

Browse files
committed
feat: add health check integration to WelcomePage
1 parent 8ac4f71 commit 6b63cbd

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/app/pages/welcome-page/welcome-page.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component } from '@angular/core'
1+
import { Component, inject, OnDestroy, OnInit } from '@angular/core'
22
import { MatButton, MatFabButton } from '@angular/material/button'
33
import { RouterLink } from '@angular/router'
44
import {
@@ -9,6 +9,9 @@ import {
99
} from '@angular/material/expansion'
1010
import { MatCardModule } from '@angular/material/card'
1111
import { MatIconModule } from '@angular/material/icon'
12+
import { HealthService } from '../../services/health-service'
13+
import { Subscription } from 'rxjs'
14+
import { environment } from '../../../environments/environment'
1215

1316
@Component({
1417
selector: 'app-welcome-page',
@@ -26,4 +29,17 @@ import { MatIconModule } from '@angular/material/icon'
2629
templateUrl: './welcome-page.html',
2730
styleUrl: './welcome-page.css',
2831
})
29-
export class WelcomePage {}
32+
export class WelcomePage implements OnInit, OnDestroy {
33+
private readonly healthService = inject(HealthService)
34+
subscription: Subscription[] = []
35+
36+
ngOnInit() {
37+
if (environment.production) {
38+
this.subscription.push(this.healthService.updateStat().subscribe())
39+
}
40+
}
41+
42+
ngOnDestroy() {
43+
this.subscription.forEach((sub) => sub.unsubscribe())
44+
}
45+
}

src/app/services/health-service.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@ export class HealthService {
1414
`${environment.api}/health`,
1515
)
1616
}
17+
18+
updateStat() {
19+
return this.httpClient.get<{ status: string; version: string; uptime: string }>(
20+
`${environment.api}/stats/new?source=feedz&timestamp=${Date.now()}`,
21+
)
22+
}
1723
}

0 commit comments

Comments
 (0)