From a4bf71cc6ab6c61876f79ca31ec54feffc195ca8 Mon Sep 17 00:00:00 2001 From: Maieul BOYER Date: Fri, 14 Nov 2025 19:25:10 +0100 Subject: [PATCH] feat(monitoring): wrote plugin for /monitoring endpoint and updated service to use them --- src/@shared/src/utils/index.ts | 7 +++++++ src/auth/src/app.ts | 2 +- src/icons/src/app.ts | 3 ++- src/user/src/app.ts | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/@shared/src/utils/index.ts b/src/@shared/src/utils/index.ts index 7e52a74..02ec07b 100644 --- a/src/@shared/src/utils/index.ts +++ b/src/@shared/src/utils/index.ts @@ -10,6 +10,13 @@ import { import { FastifyReply } from 'fastify'; import fp from 'fastify-plugin'; +export const useMonitoring = fp(async (fastify) => { + fastify.get('/monitoring', { schema: { hide: true } }, (req, res) => { + void req; + res.code(200).send('Ok'); + }); +}); + const kMakeResponseSym = Symbol('make-response-sym'); declare module 'fastify' { export interface RouteOptions { diff --git a/src/auth/src/app.ts b/src/auth/src/app.ts index 540667d..2791f28 100644 --- a/src/auth/src/app.ts +++ b/src/auth/src/app.ts @@ -23,6 +23,7 @@ declare module 'fastify' { const app: FastifyPluginAsync = async (fastify, opts): Promise => { void opts; await fastify.register(utils.useMakeResponse); + await fastify.register(utils.useMonitoring); await fastify.register(swagger.useSwagger, { service: __SERVICE_NAME }); await fastify.register(db.useDatabase as FastifyPluginAsync, {}); await fastify.register(auth.jwtPlugin as FastifyPluginAsync, {}); @@ -38,7 +39,6 @@ const app: FastifyPluginAsync = async (fastify, opts): Promise => { void fastify.register(fastifyFormBody, {}); void fastify.register(fastifyMultipart, {}); - fastify.get('/monitoring', () => 'Ok'); }; export default app; diff --git a/src/icons/src/app.ts b/src/icons/src/app.ts index 9cbabe8..7c3b2f0 100644 --- a/src/icons/src/app.ts +++ b/src/icons/src/app.ts @@ -4,6 +4,7 @@ import fastifyMultipart from '@fastify/multipart'; import { mkdir } from 'node:fs/promises'; import fp from 'fastify-plugin'; import * as db from '@shared/database'; +import * as utils from '@shared/utils'; import { authPlugin, jwtPlugin } from '@shared/auth'; // @ts-expect-error: import.meta.glob is a vite thing. Typescript doesn't know this... @@ -32,6 +33,7 @@ const app: FastifyPluginAsync = async ( void fastify.register(route as FastifyPluginAsync, {}); } + await fastify.register(utils.useMonitoring); await fastify.register(db.useDatabase as FastifyPluginAsync, {}); await fastify.register(authPlugin as FastifyPluginAsync, {}); await fastify.register(jwtPlugin as FastifyPluginAsync, {}); @@ -46,7 +48,6 @@ const app: FastifyPluginAsync = async ( fastify2.decorate('image_store', image_store); await mkdir(fastify2.image_store, { recursive: true }); })); - fastify.get('/monitoring', () => 'Ok'); }; export default app; diff --git a/src/user/src/app.ts b/src/user/src/app.ts index dbda64c..79c87fb 100644 --- a/src/user/src/app.ts +++ b/src/user/src/app.ts @@ -16,6 +16,7 @@ const routes = import.meta.glob('./routes/**/*.ts', { eager: true }); const app: FastifyPluginAsync = async (fastify, opts): Promise => { void opts; await fastify.register(utils.useMakeResponse); + await fastify.register(utils.useMonitoring); await fastify.register(swagger.useSwagger, { service: __SERVICE_NAME }); await fastify.register(db.useDatabase as FastifyPluginAsync, {}); await fastify.register(auth.jwtPlugin as FastifyPluginAsync, {}); @@ -31,7 +32,6 @@ const app: FastifyPluginAsync = async (fastify, opts): Promise => { void fastify.register(fastifyFormBody, {}); void fastify.register(fastifyMultipart, {}); - fastify.get('/monitoring', () => 'Ok'); }; export default app;