// Keeps the visitor's address available to route-cached SSR renders. // // An app rule such as `'/**': { swr }` wraps the page renderer (and any // matching server route) in Nitro's cached handler, which renders from a copy // of the request that carries no headers (only `varies` headers survive, so a // cached page never depends on one visitor's request). Reading // x-forwarded-for there would forward only the Nuxt peer, and every cache // miss would share the Journal API's rate-limit bucket. The event context is // shared with that copy, so the incoming x-forwarded-for plus the peer // address is recorded on the request hook, before the cached handler runs; // useJournalApi, /rss.xml and the sitemap source forward 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.journalForwardedFor = forwarded }) })