The Day a Service Worker Ate My API Requests: A PWA Debugging Story

February 9, 2026

The 404 That Made No Sense

So there I was, late in the evening, checking whether the new v2 API endpoints were working on production. My setup is a Go backend with a Vue frontend sitting behind Cloudflare. Nothing fancy. I opened the attractions page, popped open DevTools out of habit, and β€” 404.

GET https://gongkard.gopagodatravel.com/api/v2/poi?page=1&limit=20&poi_type=attraction&include=specific_data
Status: 404 Not Found
{"message":"NoMatchingRoute: Please double check the path and method"}

On an endpoint I literally just wrote.

"Must Be a Deploy Problem"

Naturally, my brain went straight to the deployment. The routes are new, maybe the latest binary didn't get picked up. I hopped on the server, confirmed the binary, redeployed the whole thing with ddploy anyway. Waited for it to come back up. Refreshed.

Nope. Same 404.

The Go routes file was staring right back at me with the route clearly registered:

v2POIAPI := aclrouter.NewACLBasedGroup(v2API, "/poi", auth.ResourceV2POI)
v2POIAPI.GET("", auth.ActionRead, v2POIHandler.List)

Tried cities β€” also 404. But locally? Everything worked perfectly. Same code, same binary. I redeployed a second time because, well, you never know. Still broken.

Maybe It's Cloudflare?

OK, so the server is fine. But the response headers were bugging me:

Remote Address: 172.67.181.247:443
cf-cache-status: DYNAMIC
access-control-allow-origin: https://gongkar.gopagodatravel.com

Cloudflare IP, CORS headers present β€” the request was clearly reaching my Go server. But what if Cloudflare had cached a stale 404 from before these v2 routes existed? That would explain everything. So I jumped into the Cloudflare dashboard and purged the cache.

Nothing changed.

The Surprise

At this point caching was the only suspect left in my head. Server's fine, Cloudflare's fine β€” maybe the browser itself is holding onto something stale? So I ticked "Disable cache" in DevTools, mostly just to rule it out.

Everything worked. All of it. POIs, cities, every v2 endpoint came back with proper JSON like nothing was ever wrong.

I turned it off β€” 404 again. Turned it back on β€” works.

Now here's the thing. I expected it might help if some HTTP cache was stale. But that didn't add up. If it were a regular browser cache issue, a hard refresh or Cloudflare purge would have already fixed it. The only reason "Disable cache" would work when everything else failed is if something was intercepting the request before it ever touched the network.

Then it clicked β€” the service worker. The app is a PWA. The service worker literally sits between the browser and the network, and Chrome's "Disable cache" toggle bypasses it entirely. It wasn't caching in the traditional sense at all. The service worker was grabbing my API requests and never letting them leave the browser.

The Service Worker Was the Culprit

I opened the production service worker (sw.js) and found this:

e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("index.html")))

No allowlist. No denylist. This NavigationRoute was intercepting every single navigation-like request and returning the cached index.html. When my frontend's HTTP client fired off GET /api/v2/poi, the service worker went: "Oh, a navigation request? Here's your cached index.html!" The browser then parsed that HTML, found no matching JSON, and my app's error handling displayed the 404 message.

Meanwhile, the dev service worker had this:

workbox.registerRoute(new workbox.NavigationRoute(
  workbox.createHandlerBoundToURL("index.html"),
  { allowlist: [/^\/$/] }  // only intercepts the root path
));

The dev build was correctly restrictive. The production build was not.

The Fix

One line in the Vite PWA config:

// vite.config.ts
VitePWA({
  workbox: {
    // ...existing config
    navigateFallback: 'index.html',
    navigateFallbackDenylist: [/^\/api\//],  // <-- this line
  }
})

The navigateFallbackDenylist tells Workbox: "Never intercept requests that start with /api/." Those requests go straight to the real server, untouched by the service worker.

But Wait, It Broke Again

I deployed the fix, tried again, and... still 404. For a moment I thought I'd been wrong about the whole service worker theory. But no β€” this time the culprit was Cloudflare. It had cached the old sw.js (the one without the denylist), so browsers were still downloading the broken service worker even after I'd fixed the source. One more Cloudflare cache purge and it finally worked for real.

This is what made this bug so nasty to pin down. It wasn't one problem β€” it was two problems stacked on top of each other, feeding into each other. The service worker was hijacking API requests, and Cloudflare was caching the broken service worker. Fix the service worker logic but forget Cloudflare, and it still looks broken. Purge Cloudflare but don't fix the service worker, and it still looks broken. You had to fix both, in the right order, to see any improvement at all. Each layer of caching masked the other, and at every step you could easily convince yourself you were chasing the wrong lead.

Lessons Learned

  1. When "Disable cache" fixes your API calls, suspect the service worker. It's the invisible middleware between your frontend and the network that nobody thinks about until it breaks something.

  2. Production and dev service workers can behave differently. Vite PWA plugin generates different service worker code for dev vs production builds. Always check the actual generated sw.js, not just your config.

  3. Service workers intercept more than you think. A NavigationRoute without restrictions will happily swallow your API requests and serve cached HTML instead. Always use navigateFallbackDenylist to exclude your API paths.

  4. Exhaust the obvious, then look deeper. I redeployed twice, purged Cloudflare cache, and only then thought to check the client side. The 404 was real β€” but it was being generated locally by the service worker, not by my server or any CDN.

The most maddening bugs are the ones where the server is doing nothing wrong and the client is lying to you. Service workers are powerful, but they're also invisible β€” and when they go rogue, they can make your perfectly healthy backend look completely broken.

Β© 2026 borui. All rights reserved. This content may be freely reproduced, displayed, modified, or distributed with proper attribution to borui and a link to the article: borui (2026-02-09). The Day a Service Worker Ate My API Requests: A PWA Debugging Story. https://caiborui.com/blog/2026-02-09-en-pwa-service-worker-hijacking-api-requests

@misc{borui2026-fa9f4d24,
  author = {borui},
  title = {{The Day a Service Worker Ate My API Requests: A PWA Debugging Story}},
  year = {2026},
  publisher = {borui's blog},
  url = {https://caiborui.com/blog/2026-02-09-en-pwa-service-worker-hijacking-api-requests}
}