Skip to content

Commit 29324d2

Browse files
fix(public): merge duplicate nested route registrations in publicRoutesRoutes /:username and /:username/card/:cardId were each registeredtwice — an outer call with rate-limit config but no real handler, andan inner call with the actual logic nested inside it. Fastify registeredthe outer shell and silently ignored the inner handler, meaning thebusiness logic never executed.Merged each pair into a single app.get() call that carries both therate-limit config and the handler body.Fixes #249 (#284)
1 parent 92d4620 commit 29324d2

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

apps/backend/src/routes/public.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,18 @@ interface CardLinkWithPlatform {
7777

7878
export async function publicRoutes(app: FastifyInstance) {
7979
// ─── Public Profile ───
80+
/**
81+
* GET /api/u/:username
82+
* Returns the public profile information for a user.
83+
*/
8084
app.get('/:username', {
8185
config: {
8286
rateLimit: {
8387
max: 100,
84-
timeWindow: '1 minute'
85-
}
86-
} as FastifyContextConfig
87-
}, async (request: FastifyRequest<{ Params: { username: string }; Querystring: { source?: string } }>, reply: FastifyReply) => {
88+
timeWindow: '1 minute',
89+
},
90+
},
91+
}, async (request: FastifyRequest<{ Params: { username: string } }>, reply: FastifyReply) => {
8892
const { username } = request.params;
8993

9094
const user = await app.prisma.user.findUnique({
@@ -234,19 +238,19 @@ export async function publicRoutes(app: FastifyInstance) {
234238
});
235239

236240
// ─── Public Card View ───
241+
/**
242+
* GET /api/u/:username/card/:cardId
243+
* Returns full owner profile + specific card data.
244+
* Used when viewing a card through username + cardId (e.g. QR code scans).
245+
*/
237246
app.get('/:username/card/:cardId', {
238247
config: {
239248
rateLimit: {
240249
max: 100,
241-
timeWindow: '1 minute'
242-
}
243-
} as FastifyContextConfig
244-
}, async (request: FastifyRequest<{ Params: { username: string; cardId: string }; Querystring: { source?: string } }>, reply: FastifyReply) => {
245-
/**
246-
* GET /api/public/:username/card/:cardId
247-
* Returns full owner profile + specific card data.
248-
* Used when viewing a card through username + cardId (e.g. QR code scans).
249-
*/
250+
timeWindow: '1 minute',
251+
},
252+
},
253+
}, async (request: FastifyRequest<{ Params: { username: string; cardId: string } }>, reply: FastifyReply) => {
250254
const { username, cardId } = request.params;
251255

252256
const user = await app.prisma.user.findUnique({

0 commit comments

Comments
 (0)