From eec65283a437c92635f91da85f687030584e3740 Mon Sep 17 00:00:00 2001 From: Rotimi Best Date: Tue, 19 May 2026 11:25:25 +0100 Subject: [PATCH] refactor: streamline publicWidgetsRouter definition for improved readability --- apps/api/src/routes/widgets/widgets.ts | 32 ++++++++++++++------------ 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/apps/api/src/routes/widgets/widgets.ts b/apps/api/src/routes/widgets/widgets.ts index 126803aa..9b3e0b37 100644 --- a/apps/api/src/routes/widgets/widgets.ts +++ b/apps/api/src/routes/widgets/widgets.ts @@ -20,21 +20,23 @@ const widgetPayloadKeyLimiter = createRateLimiter({ keyGenerator: (c) => `widget_payload_key:${c.req.param('publicKey')}` }); -export const publicWidgetsRouter = new Hono().use('*', publicApiCors).get( - '/:publicKey/payload', - zValidator('param', ZWidgetPublicKeyParams), - widgetPayloadIpLimiter, - widgetPayloadKeyLimiter, - async (c) => { - try { - const { publicKey } = c.req.valid('param'); - const payload = await getPublishedWidgetPayload(publicKey); +export const publicWidgetsRouter = new Hono() + .use('*', publicApiCors) + .get( + '/:publicKey/payload', + zValidator('param', ZWidgetPublicKeyParams), + widgetPayloadIpLimiter, + widgetPayloadKeyLimiter, + async (c) => { + try { + const { publicKey } = c.req.valid('param'); + const payload = await getPublishedWidgetPayload(publicKey); - c.header('Cache-Control', 'public, max-age=60, stale-while-revalidate=300'); + c.header('Cache-Control', 'public, max-age=60, stale-while-revalidate=300'); - return c.json({ success: true, data: payload }); - } catch (error) { - return handleError(c, error, 'Failed to fetch widget payload'); + return c.json({ success: true, data: payload }); + } catch (error) { + return handleError(c, error, 'Failed to fetch widget payload'); + } } - } -); + );