4 months ago
Hi Railway team,
I'm building a multi-tenant app using Next.js hosted on Railway. Each tenant has a custom domain (e.g. semprecontigo.com.br
) that is mapped internally to a dynamic route like /ongs/semprecontigo.com.br
via middleware.
I'm using revalidatePath()
from Next.js (App Router, static generation with ISR) to trigger regeneration of specific tenant pages. It works correctly for the internal route (e.g. /ongs/semprecontigo.com.br
), and the updated content is built and available.
However, the issue is: When accessing the site through the custom domain (semprecontigo.com.br
), Railway’s CDN continues to serve the cached HTML version, and the updated content is not visible.
I've confirmed that:
revalidatePath()
is triggering regeneration (works locally and on internal paths)The issue only happens when accessing via a custom domain set in Railway
The middleware correctly rewrites domain.com.br →
/ongs/domain.com.br
CDN cache appears to not be purged or invalidated even after regeneration
Is there a recommended way to bypass or control HTML caching for custom domains in Railway?
Ideally, I’d like to allow ISR and revalidation to work correctly without disabling caching for all tenants or relying on query param cache-busting.
Thanks in advance!
7 Replies
4 months ago
Hello,
At this time, we do not have a CDN of any kind in place, and we do not cache anything on our side.
Perhaps you are running into browser cache or similar, but the issue does not originate from the Railway platform.
Since this issue is outside of our control, I'm going to open this thread up to our community so they can help you!
Best,
Brody
Status changed to Awaiting User Response Railway • 4 months ago
4 months ago
This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.
Status changed to Open brody • 4 months ago
4 months ago
Brody, there's definitely something going on with caching when I configure a domain with Railway app. If it's a domain that's not registered in settings, revalidatePath works, otherwise it only works for the first time and stops.
4 months ago
I have these 2 tenant sites:
https://sites.doalink.com.br/ongs/semprecontigo.com.br
When I update the site with semprecontigo.com.br, from my cms, and revalidatePath, I only see the change the very first time I call revalidatePath. All sub-sequent calls to revalidate path for the path ongs/[domain], when domain is a registered domain doesn't work.
https://sites.doalink.com.br/ongs/leonardo.com.br
When I update the site with leonardo.com.br, from my cms, and revalidatePath, I see the changes immediately, 100% of the times.
4 months ago
Hello, perhaps you can try setting the cache rule bypass rule at your domain name hosting provider to figure out exactly where the problem lies, such as: cloudflare - Caching - Cache Rules
Attachments
wangxuedong
Hello, perhaps you can try setting the cache rule bypass rule at your domain name hosting provider to figure out exactly where the problem lies, such as: cloudflare - Caching - Cache Rules
4 months ago
Thanks for the response! I did that on the main domain and all the tenant domains and continue to see the problem
4 months ago
Hey team, thanks very much for the support! In the end, it was an issue with cache revalidation in NextJS.
In a multi-tenant setup, visitors go to the root of the website, and we internally rewrite the request to the proper path - in my cause ongs/[domain], and with a rewrite, NextJS doesn't consider it a visit to re-rerender the page.
For anyone having this problem
revalidatePath('/ongs/[tenant-domain]')
// Key: right after, you use your base domain to
fetch('sites.doalink.com.br/ongs/[tenant-domain]');
This visit without a re-write causes the re-render of the page.
Status changed to Solved uxuz • 3 months ago