Workers: not_found_handling: single-page-application - does this only work in HTTPS?

I'm trying to get a local worker working, serving an SPA via vite. I configured "not_found_handling": "single-page-application", and according to the docs, this should serve the static assets during a navigation request. Problem is, Firefox nor Chrome, will send the Sec-Fetch-Mode: navigate header if the protocol is HTTP, only in HTTPS. I just want to confirm this known/expected, or if something's wrong with my setup.
9 Replies
ALECKS
ALECKSOP6mo ago
Oh, if I use localhost it works, but any other domain does not work on http http://localhost/something < sends the Sec-Fetch-Mode header https://example.com < sends it http://example.com < does not send it
James
James6mo ago
cc @korinne - this is an oversight with using the sec headers I imagine 🙃
Razboy20
Razboy206mo ago
(cc. @James Opstad)
James Opstad
James Opstad6mo ago
This is the same issue tracked here - https://github.com/cloudflare/workers-sdk/issues/9109. You will soon be able to use static routing to opt out of the sec-fetch-mode handling and define routes that should be handled by the Worker manually. I'll link to the release notes when it's available, which should be tomorrow. Docs to follow soon.
GitHub
cloudflare/workers-sdk
⛅️ Home to Wrangler, the CLI for Cloudflare Workers® - cloudflare/workers-sdk
ALECKS
ALECKSOP6mo ago
any rough idea when this will be released?
James Opstad
James Opstad6mo ago
James
James6mo ago
Does setting run_worker_first to an array opt out of sec-fetch-mode with "not_found_handling": "single-page-application" by default, or do you also need to set the assets_navigation_has_no_effect compat flag? Or is the intent to have the have the user handle the SPA behaviour with run_worker_first, making "not_found_handling": "single-page-application" not really do anything? It's possible I'm missing something, just not quite understanding how this solves the explicit sec-fetch-mode header issue not being sent in non-secure contexts like HTTP, even in production, unless the intent is for users to just handle this behaviour themselves in their worker now, and serve the necessary html or whatever.
James Opstad
James Opstad6mo ago
Yes, setting run_worker_first to an array opts out of the sec-fetch-mode handling. With the run_worker_first array and "not_found_handling": "single-page-application", requests will only be routed to the User Worker if they match a route in the array. Otherwise they will match an asset or fall back to index.html. The way I think of it is that you can have the old implicit routing (which interprets sec-fetch-mode) or opt in to explicit routing by using run_worker_first.
ALECKS
ALECKSOP6mo ago
I can confirm that I can now load SPA routes, deeper than / using run_worker_first with an array, using HTTP!

Did you find this page helpful?