refactor: streamline publicWidgetsRouter definition for improved readability
This commit is contained in:
@@ -20,21 +20,23 @@ const widgetPayloadKeyLimiter = createRateLimiter({
|
|||||||
keyGenerator: (c) => `widget_payload_key:${c.req.param('publicKey')}`
|
keyGenerator: (c) => `widget_payload_key:${c.req.param('publicKey')}`
|
||||||
});
|
});
|
||||||
|
|
||||||
export const publicWidgetsRouter = new Hono().use('*', publicApiCors).get(
|
export const publicWidgetsRouter = new Hono()
|
||||||
'/:publicKey/payload',
|
.use('*', publicApiCors)
|
||||||
zValidator('param', ZWidgetPublicKeyParams),
|
.get(
|
||||||
widgetPayloadIpLimiter,
|
'/:publicKey/payload',
|
||||||
widgetPayloadKeyLimiter,
|
zValidator('param', ZWidgetPublicKeyParams),
|
||||||
async (c) => {
|
widgetPayloadIpLimiter,
|
||||||
try {
|
widgetPayloadKeyLimiter,
|
||||||
const { publicKey } = c.req.valid('param');
|
async (c) => {
|
||||||
const payload = await getPublishedWidgetPayload(publicKey);
|
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 });
|
return c.json({ success: true, data: payload });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return handleError(c, error, 'Failed to fetch widget payload');
|
return handleError(c, error, 'Failed to fetch widget payload');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user