From 22cf6ec48197b9e193c1a9ada3dcfba7fb2976de Mon Sep 17 00:00:00 2001 From: Mehtab Singh Date: Sat, 23 May 2026 18:52:22 +0530 Subject: [PATCH] =?UTF-8?q?fix(public):=20merge=20duplicate=20nested=20rou?= =?UTF-8?q?te=20registrations=20in=20publicRoutesRoutes=20/:username=20and?= =?UTF-8?q?=20/:username/card/:cardId=20were=20each=20registeredtwice=20?= =?UTF-8?q?=E2=80=94=20an=20outer=20call=20with=20rate-limit=20config=20bu?= =?UTF-8?q?t=20no=20real=20handler,=20andan=20inner=20call=20with=20the=20?= =?UTF-8?q?actual=20logic=20nested=20inside=20it.=20Fastify=20registeredth?= =?UTF-8?q?e=20outer=20shell=20and=20silently=20ignored=20the=20inner=20ha?= =?UTF-8?q?ndler,=20meaning=20thebusiness=20logic=20never=20executed.Merge?= =?UTF-8?q?d=20each=20pair=20into=20a=20single=20app.get()=20call=20that?= =?UTF-8?q?=20carries=20both=20therate-limit=20config=20and=20the=20handle?= =?UTF-8?q?r=20body.Fixes=20#249?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/backend/src/routes/public.ts | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/apps/backend/src/routes/public.ts b/apps/backend/src/routes/public.ts index 6820072..01f1378 100644 --- a/apps/backend/src/routes/public.ts +++ b/apps/backend/src/routes/public.ts @@ -77,14 +77,18 @@ interface CardLinkWithPlatform { export async function publicRoutes(app: FastifyInstance) { // ─── Public Profile ─── + /** + * GET /api/u/:username + * Returns the public profile information for a user. + */ app.get('/:username', { config: { rateLimit: { max: 100, - timeWindow: '1 minute' - } - } as FastifyContextConfig - }, async (request: FastifyRequest<{ Params: { username: string }; Querystring: { source?: string } }>, reply: FastifyReply) => { + timeWindow: '1 minute', + }, + }, + }, async (request: FastifyRequest<{ Params: { username: string } }>, reply: FastifyReply) => { const { username } = request.params; const user = await app.prisma.user.findUnique({ @@ -234,19 +238,19 @@ export async function publicRoutes(app: FastifyInstance) { }); // ─── Public Card View ─── + /** + * GET /api/u/:username/card/:cardId + * Returns full owner profile + specific card data. + * Used when viewing a card through username + cardId (e.g. QR code scans). + */ app.get('/:username/card/:cardId', { config: { rateLimit: { max: 100, - timeWindow: '1 minute' - } - } as FastifyContextConfig - }, async (request: FastifyRequest<{ Params: { username: string; cardId: string }; Querystring: { source?: string } }>, reply: FastifyReply) => { - /** - * GET /api/public/:username/card/:cardId - * Returns full owner profile + specific card data. - * Used when viewing a card through username + cardId (e.g. QR code scans). - */ + timeWindow: '1 minute', + }, + }, + }, async (request: FastifyRequest<{ Params: { username: string; cardId: string } }>, reply: FastifyReply) => { const { username, cardId } = request.params; const user = await app.prisma.user.findUnique({