@@ -5,7 +5,6 @@ import { isDatabaseReachable } from "../../../shared/db/client";
5
5
import { env } from "../../../shared/utils/env" ;
6
6
import { isRedisReachable } from "../../../shared/utils/redis/redis" ;
7
7
import { thirdwebClientId } from "../../../shared/utils/sdk" ;
8
- import { createCustomError } from "../../middleware/error" ;
9
8
10
9
type EngineFeature =
11
10
| "KEYPAIR_AUTH"
@@ -15,7 +14,9 @@ type EngineFeature =
15
14
| "SMART_BACKEND_WALLETS" ;
16
15
17
16
const ReplySchemaOk = Type . Object ( {
18
- status : Type . String ( ) ,
17
+ db : Type . Boolean ( ) ,
18
+ redis : Type . Boolean ( ) ,
19
+ auth : Type . Boolean ( ) ,
19
20
engineVersion : Type . Optional ( Type . String ( ) ) ,
20
21
engineTier : Type . Optional ( Type . String ( ) ) ,
21
22
features : Type . Array (
@@ -54,29 +55,22 @@ export async function healthCheck(fastify: FastifyInstance) {
54
55
} ,
55
56
} ,
56
57
handler : async ( _ , res ) => {
57
- if ( ! ( await isDatabaseReachable ( ) ) ) {
58
- throw createCustomError (
59
- "The database is unreachable." ,
60
- StatusCodes . SERVICE_UNAVAILABLE ,
61
- "FAILED_HEALTHCHECK" ,
62
- ) ;
63
- }
58
+ const db = await isDatabaseReachable ( ) ;
59
+ const redis = await isRedisReachable ( ) ;
60
+ const auth = await isAuthValid ( ) ;
61
+ const isHealthy = db && redis && auth ;
64
62
65
- if ( ! ( await isRedisReachable ( ) ) ) {
66
- throw createCustomError (
67
- "Redis is unreachable." ,
68
- StatusCodes . SERVICE_UNAVAILABLE ,
69
- "FAILED_HEALTHCHECK" ,
70
- ) ;
71
- }
72
-
73
- res . status ( StatusCodes . OK ) . send ( {
74
- status : "OK" ,
75
- engineVersion : env . ENGINE_VERSION ,
76
- engineTier : env . ENGINE_TIER ?? "SELF_HOSTED" ,
77
- features : getFeatures ( ) ,
78
- clientId : thirdwebClientId ,
79
- } ) ;
63
+ res
64
+ . status ( isHealthy ? StatusCodes . OK : StatusCodes . SERVICE_UNAVAILABLE )
65
+ . send ( {
66
+ db,
67
+ redis,
68
+ auth,
69
+ engineVersion : env . ENGINE_VERSION ,
70
+ engineTier : env . ENGINE_TIER ?? "SELF_HOSTED" ,
71
+ features : getFeatures ( ) ,
72
+ clientId : thirdwebClientId ,
73
+ } ) ;
80
74
} ,
81
75
} ) ;
82
76
}
@@ -95,3 +89,16 @@ const getFeatures = (): EngineFeature[] => {
95
89
96
90
return features ;
97
91
} ;
92
+
93
+ async function isAuthValid ( ) {
94
+ try {
95
+ const resp = await fetch ( "https://api.thirdweb.com/v2/keys/use" , {
96
+ headers : {
97
+ "x-secret-key" : env . THIRDWEB_API_SECRET_KEY ,
98
+ } ,
99
+ } ) ;
100
+ return resp . ok ;
101
+ } catch {
102
+ return false ;
103
+ }
104
+ }
0 commit comments