Files
vue-faq-layer/server/plugins/faq-client-address.ts
Jakub Zych 2d62924b78 feat: FaqBlock layer for the SummerCMS FAQ API
- typed client and useFaq/useFaqApi (SSR, faq:<slug>:<locale> key,
  server and public bases, x-forwarded-for forwarded also on cached renders)
- FaqBlock, FaqList and FaqItem: native details, exclusive and openFirst,
  server-sanitized description and answers, nothing or #fallback on 404,
  error or no items
- FAQ tokens and base CSS with the .faq-html rules, README
- node client tests and a playground SSR smoke against a fixture API
2026-10-12 18:22:03 +02:00

18 lines
827 B
TypeScript

// Keeps the visitor's address available to route-cached SSR renders.
//
// An app rule such as `'/**': { swr }` renders cached pages from a copy of
// the request without headers. The FAQ API throttles per client address,
// so forwarding only the Nuxt peer would put every cache miss in one bucket.
// The event context is shared with that copy, so the incoming
// x-forwarded-for plus the peer address is recorded here, before the cached
// handler runs, and useFaqApi forwards it.
export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook('request', (event) => {
const forwarded = [getRequestHeader(event, 'x-forwarded-for'), event.node.req.socket?.remoteAddress]
.filter((v): v is string => typeof v === 'string' && v !== '')
.join(', ')
event.context.faqForwardedFor = forwarded
})
})