// 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 }) })