A developer creates a health check endpoint for NestJS microservices by building a shared health module. The process includes defining a controller, configuring the module, exporting it to the service modules, testing with a GET request, and committing the changes to trigger a CodeBuild deployment.
Length 2:41
Captions English (Generated), Spanish (Auto-translated), French (Auto-translated), Korean (Auto-translated), Portuguese (Auto-translated), Vietnamese (Auto-translated) #kubernetes #nestjs #health-check #microservices #coding #software-development #load-balancer #ingress #git #codebuild
0:00 We also need to specify a route that will serve as a health check 0:03 endpoint for this ingress. By default, Kubernetes Engine 0:08 will launch health check endpoints at the root path of 0:12 each ingress resources here to make sure that the load balancer is healthy. 0:16 So in order to make sure that it's reported as healthy 0:19 and our application is 0:20 actually routed to, we're gonna go ahead 0:22 and create a new route in both the 0:24 reservations and auth services to respond to this health 0:28 check. Since we want this to be common to both of 0:31 the services, we'll 0:32 go ahead and create it in our libs/common folder. 0:36 So go ahead and create a new directory called health, and inside 0:40 of here, we'll create a health.controller, 0:44 and this will be a NestJS controller called 0:48 HealthController. We'll go ahead and specify the path for this controller 0:52 to be at the root of the service, and then we'll specify a single GET 0:56 route here called health that will simply return true to 1:00 indicate that the application can respond to HTTP traffic. 1:04 We'll go ahead and create a new health.module that will be a 1:08 new @module from NestJS common called 1:11 HealthModule. 1:14 And we'll specify our controller that we set up in the 1:17 controllers array. 1:20 Now we'll go ahead and specify an index.ts where we go ahead 1:24 and 1:24 export everything from the 1:27 health.module. And then at the root 1:31 index.ts, we'll export everything 1:34 from the health folder. So now we can come 1:38 in at the reservation service in the ReservationsModule, 1:42 and all we have to do is import the 1:44 HealthModule directly from app/common, and we 1:48 get the health controller out of the box. 1:51 So we'll go ahead and do the same thing in the AuthModule 1:55 by importing the HealthModule here from app/common. 2:00 So if our containers are running, we can then launch a
The rest of the transcript is for members.
Sign in