@@ -6,38 +6,27 @@ import { HttpProvider, HttpResponse, Route, Heart, HttpProviderOptions } from ".
6
6
* Check the heartbeat.
7
7
*/
8
8
export class HealthHttpProvider extends HttpProvider {
9
+ public constructor ( options : HttpProviderOptions , private readonly heart : Heart ) {
10
+ super ( options )
11
+ }
9
12
10
- public constructor (
11
- options : HttpProviderOptions ,
12
- private readonly heart : Heart
13
- ) {
14
- super ( options )
13
+ public async handleRequest ( route : Route , request : http . IncomingMessage ) : Promise < HttpResponse > {
14
+ if ( ! this . authenticated ( request ) ) {
15
+ if ( this . isRoot ( route ) ) {
16
+ return { redirect : "/login" , query : { to : route . fullPath } }
17
+ }
18
+ throw new HttpError ( "Unauthorized" , HttpCode . Unauthorized )
15
19
}
16
20
17
- private alive ( ) : Boolean {
18
- const now = Date . now ( )
19
- return ( now - this . heart . lastHeartbeat < this . heart . heartbeatInterval )
21
+ const result = {
22
+ cache : false ,
23
+ mime : "application/json" ,
24
+ content : {
25
+ status : this . heart . alive ( ) ? "alive" : "expired" ,
26
+ lastHeartbeat : this . heart . lastHeartbeat ,
27
+ } ,
20
28
}
21
29
22
- public async handleRequest ( route : Route , request : http . IncomingMessage ) : Promise < HttpResponse > {
23
- if ( ! this . authenticated ( request ) ) {
24
- if ( this . isRoot ( route ) ) {
25
- return { redirect : "/login" , query : { to : route . fullPath } }
26
- }
27
- throw new HttpError ( "Unauthorized" , HttpCode . Unauthorized )
28
- }
29
-
30
- const result = {
31
- cache : false ,
32
- mime : 'application/json' ,
33
- content : {
34
- status : ( this . alive ( ) ) ? 'alive' : 'expired' ,
35
- lastHeartbeat : this . heart . lastHeartbeat
36
-
37
- }
38
- }
39
-
40
- return result
41
-
42
- }
30
+ return result
31
+ }
43
32
}
0 commit comments