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
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 itcc @korinne - this is an oversight with using the sec headers I imagine 🙃
(cc. @James Opstad)
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
any rough idea when this will be released?
Just been released now in v1.7.0. Here are the details - https://github.com/cloudflare/workers-sdk/releases/tag/%40cloudflare%2Fvite-plugin%401.7.0.
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.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.I can confirm that I can now load SPA routes, deeper than
/ using run_worker_first with an array, using HTTP!