Is it possible to consider host header during ISR caching?
hey, when using routeRules isr, is it possible to consider the host header as well? i am working on a multi-tenanted app and trying to cache the response per tenant.
2 Replies
Hi @Felix. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Yes, when using
routeRules with ISR (Incremental Static Regeneration) in a multi-tenant application, you can consider the host header by using the cache.varies option in your route rules.
When utilizing Hybrid Rendering with cache strategies like ISR, all incoming request headers are dropped when handling cached responses via the Nitro caching layer. This means that by default, useRequestURL() will return localhost for the host property, which isn't ideal for multi-tenant applications.
To make your ISR caching consider the host header, you need to specify which headers should be considered when caching and serving responses:
By adding the cache.varies option with host and x-forwarded-host, you're telling Nitro to create separate cache entries for different hostnames, which is essential for multi-tenant applications where different tenants access your app through different domains.
This approach is specifically documented for multi-tenant environments in the useRequestURL documentation, which mentions:
When utilizing Hybrid Rendering with cache strategies, all incoming request headers are dropped when handling the cached responses via the Nitro caching layer (meaning---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------useRequestURLwill returnlocalhostfor thehost). You can define thecache.variesoption to specify headers that will be considered when caching and serving the responses, such ashostandx-forwarded-hostfor multi-tenant environments.
<@223579303122567168> Kapa.ai is still learning and improving, please let me know how I did by reacting below.