From 16711a15169b588d9a1e500ba6ce5887a4ad1929 Mon Sep 17 00:00:00 2001 From: Harsh R <53080940+fullstackninja864@users.noreply.github.com> Date: Fri, 10 Nov 2023 07:42:13 +0530 Subject: [PATCH] feature(serve): added health endpoint (#350) * feature(serve): added health endpoint * lint fix --- .vscode/settings.json | 6 +- apps/server/package.json | 1 + apps/server/src/app.module.ts | 2 + apps/server/src/health/HealthController.ts | 15 +++ apps/server/src/health/HealthModule.ts | 11 +++ apps/web/src/pages/tx/[tid].tsx | 6 +- pnpm-lock.yaml | 107 +++++++++++++++++++-- pnpm-workspace.yaml | 2 +- 8 files changed, 135 insertions(+), 15 deletions(-) create mode 100644 apps/server/src/health/HealthController.ts create mode 100644 apps/server/src/health/HealthModule.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 0b868be7..587e857e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -21,9 +21,5 @@ "**/.DS_Store": true, "**/Thumbs.db": true }, - "cSpell.words": [ - "birthdaycloud", - "fastify", - "Middie" - ] + "cSpell.words": ["birthdaycloud", "fastify", "Middie"] } diff --git a/apps/server/package.json b/apps/server/package.json index eda96e06..f3877d71 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -61,6 +61,7 @@ "@nestjs/config": "^3.1.1", "@nestjs/core": "^10.2.5", "@nestjs/platform-express": "^10.2.5", + "@nestjs/terminus": "^10.1.1", "@nestjs/throttler": "^5.0.1", "@waveshq/standard-defichain-jellyfishsdk": "^2.6.1", "@waveshq/walletkit-core": "^1.3.4", diff --git a/apps/server/src/app.module.ts b/apps/server/src/app.module.ts index 8b3d8198..fd0195aa 100644 --- a/apps/server/src/app.module.ts +++ b/apps/server/src/app.module.ts @@ -7,6 +7,7 @@ import { AppController } from './app.controller'; import { AppService } from './app.service'; import { appConfig, ENV_VALIDATION_SCHEMA } from './AppConfig'; import { FaucetModule } from './faucet/FaucetModule'; +import { HealthModule } from './health/HealthModule'; @Module({ imports: [ @@ -22,6 +23,7 @@ import { FaucetModule } from './faucet/FaucetModule'; }, ]), FaucetModule, + HealthModule, ], controllers: [AppController], providers: [ diff --git a/apps/server/src/health/HealthController.ts b/apps/server/src/health/HealthController.ts new file mode 100644 index 00000000..4ff5e870 --- /dev/null +++ b/apps/server/src/health/HealthController.ts @@ -0,0 +1,15 @@ +import { Controller, Get } from '@nestjs/common'; +import { HealthCheck, HealthCheckService } from '@nestjs/terminus'; +import { SkipThrottle } from '@nestjs/throttler'; + +@Controller('health') +export class HealthController { + constructor(private readonly health: HealthCheckService) {} + + @SkipThrottle() + @Get() + @HealthCheck() + check() { + return this.health.check([]); + } +} diff --git a/apps/server/src/health/HealthModule.ts b/apps/server/src/health/HealthModule.ts new file mode 100644 index 00000000..a9a32d83 --- /dev/null +++ b/apps/server/src/health/HealthModule.ts @@ -0,0 +1,11 @@ +import { Module } from '@nestjs/common'; +import { TerminusModule } from '@nestjs/terminus'; + +import { HealthController } from './HealthController'; + +@Module({ + imports: [TerminusModule], + controllers: [HealthController], + providers: [], +}) +export class HealthModule {} diff --git a/apps/web/src/pages/tx/[tid].tsx b/apps/web/src/pages/tx/[tid].tsx index 3534155e..9a0ad060 100644 --- a/apps/web/src/pages/tx/[tid].tsx +++ b/apps/web/src/pages/tx/[tid].tsx @@ -32,7 +32,7 @@ export default function Transaction({ const gasPrice = { value: txDetails.gasPrice, symbol: GWEI_SYMBOL }; const gasUsedPercentage = new BigNumber(txDetails.gasUsed) .dividedBy(txDetails.gasLimit) - .multipliedBy(100) + .multipliedBy(100); const timeDuration = getDuration(Number(txDetails.timeInSec)); const timeInUTC = formatDateToUTC(txDetails.timestamp); @@ -225,7 +225,9 @@ export default function Transaction({ gasPrice={gasPrice} gasLimit={txDetails.gasLimit} gasUsed={txDetails.gasUsed} - gasUsedPercentage={gasUsedPercentage.isNaN() ? "0" : gasUsedPercentage.toFixed(2)} + gasUsedPercentage={ + gasUsedPercentage.isNaN() ? "0" : gasUsedPercentage.toFixed(2) + } nonce={txDetails.nonce} from={txDetails.from} to={txDetails.to} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 658f5072..4a0f7498 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -54,6 +54,9 @@ importers: '@nestjs/platform-express': specifier: ^10.2.5 version: 10.2.8(@nestjs/common@10.2.8)(@nestjs/core@10.2.8) + '@nestjs/terminus': + specifier: ^10.1.1 + version: 10.1.1(@nestjs/common@10.2.8)(@nestjs/core@10.2.8)(reflect-metadata@0.1.13)(rxjs@7.8.1) '@nestjs/throttler': specifier: ^5.0.1 version: 5.0.1(@nestjs/common@10.2.8)(@nestjs/core@10.2.8)(reflect-metadata@0.1.13) @@ -3365,6 +3368,62 @@ packages: - chokidar dev: true + /@nestjs/terminus@10.1.1(@nestjs/common@10.2.8)(@nestjs/core@10.2.8)(reflect-metadata@0.1.13)(rxjs@7.8.1): + resolution: {integrity: sha512-aDoPK/uaR9PHn56xzand6zqpp+S3Ibm+y/OrG3M01F1WnScLfo29hbS6MdnIMqmVRAS11r/8X3xWTSo8TT/Lig==} + peerDependencies: + '@grpc/grpc-js': '*' + '@grpc/proto-loader': '*' + '@mikro-orm/core': '*' + '@mikro-orm/nestjs': '*' + '@nestjs/axios': ^1.0.0 || ^2.0.0 || ^3.0.0 + '@nestjs/common': ^9.0.0 || ^10.0.0 + '@nestjs/core': ^9.0.0 || ^10.0.0 + '@nestjs/microservices': ^9.0.0 || ^10.0.0 + '@nestjs/mongoose': ^9.0.0 || ^10.0.0 + '@nestjs/sequelize': ^9.0.0 || ^10.0.0 + '@nestjs/typeorm': ^9.0.0 || ^10.0.0 + '@prisma/client': '*' + mongoose: '*' + reflect-metadata: 0.1.x + rxjs: 7.x + sequelize: '*' + typeorm: '*' + peerDependenciesMeta: + '@grpc/grpc-js': + optional: true + '@grpc/proto-loader': + optional: true + '@mikro-orm/core': + optional: true + '@mikro-orm/nestjs': + optional: true + '@nestjs/axios': + optional: true + '@nestjs/microservices': + optional: true + '@nestjs/mongoose': + optional: true + '@nestjs/sequelize': + optional: true + '@nestjs/typeorm': + optional: true + '@prisma/client': + optional: true + mongoose: + optional: true + sequelize: + optional: true + typeorm: + optional: true + dependencies: + '@nestjs/common': 10.2.8(class-validator@0.14.0)(reflect-metadata@0.1.13)(rxjs@7.8.1) + '@nestjs/core': 10.2.8(@nestjs/common@10.2.8)(@nestjs/platform-express@10.2.8)(reflect-metadata@0.1.13)(rxjs@7.8.1) + boxen: 5.1.2 + check-disk-space: 3.4.0 + reflect-metadata: 0.1.13 + rxjs: 7.8.1 + dev: false + /@nestjs/testing@10.2.8(@nestjs/common@10.2.8)(@nestjs/core@10.2.8)(@nestjs/platform-express@10.2.8): resolution: {integrity: sha512-9Kj5IQhM67/nj/MT6Wi2OmWr5YQnCMptwKVFrX1TDaikpY12196v7frk0jVjdT7wms7rV07GZle9I2z0aSjqtQ==} peerDependencies: @@ -6103,6 +6162,12 @@ packages: uri-js: 4.4.1 dev: true + /ansi-align@3.0.1: + resolution: {integrity: sha512-IOfwwBF5iczOjp/WeY4YxyjqAFMQoZufdQWDd19SEExbVLNXqvpzSJ/M7Za4/sCPmQ0+GRquoA7bGcINcxew6w==} + dependencies: + string-width: 4.2.3 + dev: false + /ansi-colors@4.1.3: resolution: {integrity: sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==} engines: {node: '>=6'} @@ -6773,6 +6838,20 @@ packages: text-encoding-utf-8: 1.0.2 dev: false + /boxen@5.1.2: + resolution: {integrity: sha512-9gYgQKXx+1nP8mP7CzFyaUARhg7D3n1dF/FnErWmu9l6JvGpNUN278h0aSb+QjoiKSWG+iZ3uHrcqk0qrY9RQQ==} + engines: {node: '>=10'} + dependencies: + ansi-align: 3.0.1 + camelcase: 6.3.0 + chalk: 4.1.2 + cli-boxes: 2.2.1 + string-width: 4.2.3 + type-fest: 0.20.2 + widest-line: 3.1.0 + wrap-ansi: 7.0.0 + dev: false + /bplist-parser@0.2.0: resolution: {integrity: sha512-z0M+byMThzQmD9NILRniCUXYsYpjwnlO8N5uCFaCqIOpqRsJCrQL9NK3JsD67CN5a08nF5oIL2bD6loTdHOuKw==} engines: {node: '>= 5.10.0'} @@ -6973,7 +7052,6 @@ packages: /camelcase@6.3.0: resolution: {integrity: sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==} engines: {node: '>=10'} - dev: true /camelize@1.0.1: resolution: {integrity: sha512-dU+Tx2fsypxTgtLoE36npi3UqcjSSMNYfkqgmoEhtZrraP5VWq0K7FkWVTYa8eMPtnU/G2txVsfdCJTn9uzpuQ==} @@ -7031,6 +7109,11 @@ packages: resolution: {integrity: sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA==} dev: false + /check-disk-space@3.4.0: + resolution: {integrity: sha512-drVkSqfwA+TvuEhFipiR1OC9boEGZL5RrWvVsOthdcvQNXyCCuKkEiTOTXZ7qxSf/GLwq4GvzfrQD/Wz325hgw==} + engines: {node: '>=16'} + dev: false + /check-more-types@2.24.0: resolution: {integrity: sha512-Pj779qHxV2tuapviy1bSZNEL1maXr13bPYpsvSDB68HlYcYuhlDrmGd63i0JHMCLKzc7rUSNIrpdJlhVlNwrxA==} engines: {node: '>= 0.8.0'} @@ -7114,6 +7197,11 @@ packages: engines: {node: '>=6'} dev: true + /cli-boxes@2.2.1: + resolution: {integrity: sha512-y4coMcylgSCdVinjiDBuR8PCC2bLjyGTwEmPb9NHR/QaNU6EUOXcTY/s6VjGMD6ENSEaeQYHCY0GNGS5jfMwPw==} + engines: {node: '>=6'} + dev: false + /cli-cursor@3.1.0: resolution: {integrity: sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==} engines: {node: '>=8'} @@ -8596,7 +8684,7 @@ packages: /eslint-import-resolver-node@0.3.9: resolution: {integrity: sha512-WFj2isz22JahUv+B788TlO3N6zL3nNJGU8CcZbPZvVEkBPaJdCV4vy5wyghty5ROFbCRnm132v8BScu5/1BQ8g==} dependencies: - debug: 3.2.7(supports-color@5.5.0) + debug: 3.2.7(supports-color@8.1.1) is-core-module: 2.13.1 resolve: 1.22.8 transitivePeerDependencies: @@ -8648,7 +8736,7 @@ packages: optional: true dependencies: '@typescript-eslint/parser': 6.9.1(eslint@8.52.0)(typescript@5.2.2) - debug: 3.2.7(supports-color@5.5.0) + debug: 3.2.7(supports-color@8.1.1) eslint: 8.52.0 eslint-import-resolver-node: 0.3.9 eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@6.9.1)(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.0)(eslint@8.52.0) @@ -8708,7 +8796,7 @@ packages: array.prototype.findlastindex: 1.2.3 array.prototype.flat: 1.3.2 array.prototype.flatmap: 1.3.2 - debug: 3.2.7(supports-color@5.5.0) + debug: 3.2.7(supports-color@8.1.1) doctrine: 2.1.0 eslint: 8.52.0 eslint-import-resolver-node: 0.3.9 @@ -8743,7 +8831,7 @@ packages: array.prototype.findlastindex: 1.2.3 array.prototype.flat: 1.3.2 array.prototype.flatmap: 1.3.2 - debug: 3.2.7(supports-color@5.5.0) + debug: 3.2.7(supports-color@8.1.1) doctrine: 2.1.0 eslint: 8.52.0 eslint-import-resolver-node: 0.3.9 @@ -15702,7 +15790,6 @@ packages: /type-fest@0.20.2: resolution: {integrity: sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==} engines: {node: '>=10'} - dev: true /type-fest@0.21.3: resolution: {integrity: sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==} @@ -16336,6 +16423,13 @@ packages: dependencies: isexe: 2.0.0 + /widest-line@3.1.0: + resolution: {integrity: sha512-NsmoXalsWVDMGupxZ5R08ka9flZjjiLvHVAWYOKtiKM8ujtZWr9cRffak+uSE48+Ob8ObalXpwyeUiyDD6QFgg==} + engines: {node: '>=8'} + dependencies: + string-width: 4.2.3 + dev: false + /wif@2.0.6: resolution: {integrity: sha512-HIanZn1zmduSF+BQhkE+YXIbEiH0xPr1012QbFEGB0xsKqJii0/SqJjyn8dFv6y36kOznMgMB+LGcbZTJ1xACQ==} dependencies: @@ -16363,7 +16457,6 @@ packages: ansi-styles: 4.3.0 string-width: 4.2.3 strip-ansi: 6.0.1 - dev: true /wrap-ansi@8.1.0: resolution: {integrity: sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 3e712d3c..3ff5faaa 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,3 +1,3 @@ packages: - "apps/*" - - "packages/*" \ No newline at end of file + - "packages/*"