Skip to content
  • English Deutsch

benjamin-abt.com

Performance is a feature | Cloud - AI - Azure - .NET - Sustainability

  • Home
  • Blog
  • Portfolio
    • Overview
    • Workshops & Training
    • Publications
  • Contact
  • Home
  • Blog

Serve SPAs correctly on Cloudflare Workers

Serve SPAs correctly on Cloudflare Workers
January 5, 2026 2 min read BEN ABT
Cloudflare Workers React SPA DevOps

Single Page Applications like React expect the server to always return index.html and let the client-side router take over. On Cloudflare Workers you can do that without custom code as long as wrangler.toml is set up correctly. This post shows the minimal configuration and why two options are essential for SPAs.

The SPA problem on the edge

A deployed SPA usually contains compiled assets plus one index.html. Deep links like /dashboard/settings should load the same index.html and let the client router render the view. Without a rewrite you get 404s because the edge tries to find a physical file dashboard/settings that does not exist.

The two crucial wrangler.toml flags

Cloudflare added built-in SPA handling. Set both options in your wrangler.toml:

TOML
 1# wrangler.toml
 2name = "my-react-app"
 3compatibility_date = "2024-11-01" # this is specific to your project
 4
 5[assets]
 6# Forces URLs like /app/ to become /app/ so relative links stay correct
 7html_handling = "force-trailing-slash"
 8
 9# Always return your SPA shell (index.html) for unknown routes
10not_found_handling = "single-page-application"
  • html_handling = "force-trailing-slash" ensures that HTML requests end with a trailing slash. That keeps relative asset links like "./static/js/main.js" valid and avoids mixed path resolution, especially when users paste URLs without the slash.
  • not_found_handling = "single-page-application" tells the Worker runtime to serve your SPA entry point instead of a 404 for any route that is not a real asset. This is the key to make deep links work.

Verify your deployment

  1. Build the React app: npm run build.
  2. Deploy: wrangler deploy.
  3. Open deep links directly (e.g., /settings/profile). If everything is configured, the page loads without 404 and the client router renders the correct view.

Troubleshooting

  • Still getting 404? Check that not_found_handling is set to single-page-application and that the assets section is under the root of wrangler.toml.
  • CSS or JS missing? Trailing slashes might be the issue. Keep html_handling = "force-trailing-slash" so relative paths resolve correctly.
  • Mixed content or wrong base path? Ensure your React build uses relative asset paths (the default for create-react-app) and that your Worker domain matches the homepage setting if you changed it.

Takeaway

Two lines in wrangler.toml are enough to make React (and any SPA) work on Cloudflare Workers without custom rewrites:

  • html_handling = "force-trailing-slash"
  • not_found_handling = "single-page-application"

Set them once, deploy and your SPA will be correctly served for every deep link.

Related articles

Cloudflare Workers with wrangler.toml: Preview URLs, production routes and SEO-safe SPA handling

May 10, 2026 - 9 min read

Cloudflare Workers with wrangler.toml: Preview URLs, production routes and SEO-safe SPA handling

Cloudflare Workers can separate production and preview traffic cleanly without sacrificing canonical URL control. For search visibility, …

Automate Pull Request Comments with GitHub Actions

Jan 4, 2026 - 2 min read

Automate Pull Request Comments with GitHub Actions

When working with Pull Requests (PRs) in GitHub, it is often helpful to provide immediate feedback or relevant information directly in the …

Scheduled Builds for Cloudflare Deployments with GitHub Actions

Jul 14, 2025 - 4 min read

Scheduled Builds for Cloudflare Deployments with GitHub Actions

Static site generators like Hugo do not have a built-in mechanism to automatically publish content–such as blog posts–at a specific time. If …


BEN ABT

BEN ABT

Ben is Chief Engineering Officer and Principal Software Engineer at Medialesson.de, with a strong focus on .NET and Microsoft Azure. In his professional role, he designs and builds highly scalable platforms for hybrid and cloud-based scenarios. He also advises companies and C-levels on migrating to the sovereign cloud.

He runs myCSharp.de, the largest and most active German-speaking C# community forum, actively contributes to both his own and external open-source projects and regularly shares his knowledge through his blog, at community events, conferences and as a writer for technical magazines.

Let's Work Together

Looking for an experienced Platform Architect or Engineer for your next project? Whether it's cloud migration, platform modernization or building new solutions from scratch - I'm here to help you succeed.

New Platforms

Modernization

Training & Consulting

Contact Me
X Facebook LinkedIn WhatsApp
Back Next Blog Post

Open for work!

Contact Me
BEN ABT BEN ABT Software Engineer · Microsoft MVP Passionate about .NET, Azure, performance optimization and sustainable software engineering.

Medialesson GmbH Logo

Microsoft MVP Logo

Recent posts

View all
Production Rate Limiting in ASP.NET Core

Production Rate Limiting in ASP.NET Core

Nov 3, 2026
The Big Decimal Bugfix with .NET 11

The Big Decimal Bugfix with .NET 11

Nov 2, 2026
Distroless, Chiseled or Alpine: Choosing a .NET Base Image

Distroless, Chiseled or Alpine: Choosing a .NET Base Image

Oct 27, 2026
Stop Using nginx as Your Default Static File Server in Docker

Stop Using nginx as Your Default Static File Server in …

Oct 24, 2026
Containerizing .NET in 2026 Without a Dockerfile

Containerizing .NET in 2026 Without a Dockerfile

Oct 20, 2026

Tags

.NET (195) Csharp (99) ASP.NET Core (49) Azure (41) DevOps (17) Docker (15) Microsoft (14) EF Core (11) Microsoft MVP (11) Security (11) AI (10) GitHub (10) GitHub Copilot (10) ASP.NET (9) Synology (9) .NET 11 (8) Architecture (8) Raspberry (8) Azure Functions (7) Cloudflare (7)
benjamin-abt.com

About BEN

Benjamin Abt is a Software Engineer, Platform Architect and Microsoft MVP specializing in .NET, Azure, cloud architecture, performance optimization and sustainable software development.

Connect

  • Follow me on GitHub
  • Follow me on LinkedIn
  • Follow me on Mastodon
  • Microsoft MVP profile
  • Follow SchwabenCode on GitHub
  • Follow me on X

Quick Links

  • Portfolio
  • Blog
  • Workshops & Training
  • Publications
  • Get in Touch
  • Sitemap
Open for Work

© Copyright Benjamin Abt & SchwabenCode | 2011 - 2026

Content licensed under CC BY 4.0 unless otherwise noted.

  • Impressum
  • Privacy
  • Contact