a month ago
We are building a true white-label SaaS platform and are trying to use Cloudflare for SaaS Custom Hostnames with Railway.
Architecture:
Customer Domain
→ Cloudflare for SaaS Custom Hostname
→ tenants-frontend.websarathi.com (Railway service)
→ Next.js application
Examples:
- xyz.com
- admin.xyz.com
- api.xyz.com
Each customer should be able to use their own domain without us manually adding domains inside Railway.
What we observed:
-
Railway service is available at:
tenants-frontend.websarathi.com
-
Accessing:
returns:
{
"host": "tenants-frontend.websarathi.com",
"xForwardedHost": "tenants-frontend.websarathi.com"
}
-
We created a Cloudflare for SaaS custom hostname:
test-customer.atmrtx.in
-
DNS setup:
test-customer.atmrtx.in CNAME tenants-frontend.websarathi.com
-
When the hostname is NOT added as a custom domain in Railway:
returns:
HTTP 404
with header:
x-railway-fallback: true
and the Railway "The train has not arrived at the station" page.
- If we add test-customer.atmrtx.in as a custom domain in Railway, the request immediately starts working.
Question:
Does Railway Edge validate incoming Host headers before routing requests to services?
If so, is there any supported way to allow arbitrary customer domains (Cloudflare for SaaS style) without manually registering every customer hostname inside Railway?
Are Cloudflare for SaaS Custom Hostnames officially supported with Railway as the origin?
Any guidance or recommended architecture would be appreciated.
Additional context:
We are using Cloudflare for SaaS Custom Hostnames.
Customer domains are configured as:
customer-domain.com
→ CNAME
→ tenants-frontend.websarathi.com
Cloudflare then forwards traffic to our Railway service.
Our goal is a true white-label SaaS where customer domains are onboarded dynamically and we do NOT manually register each customer hostname in Railway.
Current observation:
-
If the customer hostname is NOT registered in Railway, we receive:
x-railway-fallback: true
-
If the same hostname IS registered in Railway, traffic reaches our Next.js application immediately.
Can Railway be used as the origin behind Cloudflare for SaaS custom hostnames without manually registering every customer domain?
Or does Railway Edge require explicit hostname registration for all incoming Host headers?
Additional note:
We already use Railway wildcard domains successfully for tenant websites. For example:
- silvara.websarathi.in
- kiaautocar.websarathi.in
- other dynamic subdomains
All are served by a single Railway service registered as:
*.websarathi.in
The application resolves tenants dynamically from the Host header and serves content correctly.
The issue only occurs when using Cloudflare for SaaS Custom Hostnames where customer-owned domains (e.g. customer-domain.com) are CNAME'd to our platform. In that scenario, Railway appears to return x-railway-fallback: true unless the hostname is explicitly registered.
1 Replies
a month ago
This thread has been opened as a bounty so the community can help solve it.
Status changed to Open Railway • 29 days ago
a month ago
railway does require explicit domain registration to route traffic — it validates the Host header against registered domains, so arbitrary customer domains won't work without being added manually or via API.
your best bet is to use the railway API to auto-register customer domains on onboarding. when a new customer signs up, hit the API to add their domain programmatically, no manual work needed.
cloudflare for saas as origin isn't officially supported by railway in that dynamic way, the wildcard approach only works for subdomains of a domain you already registered (like *.websarathi.com). fully custom domains like customer-domain.com need to be registered individually