Workers Vite in browser not trying to reach worker

I'm trying to rebuild my setup to deploy my React SPA together with my api in one worker. For this im using the cloudflare worker vite plugin with
json
"assets": {
"not_found_handling": "single-page-application"
}
json
"assets": {
"not_found_handling": "single-page-application"
}
now i have an issue that it always just shows not found on worker paths when accessing them in browser. This is a big issue since I have some /callback routes for auth flows I need the user to be redirected to. Anything I need to configure?
3 Replies
makisuo
makisuoOP3w ago
Manage to make it "run" with using

"assets": {
// "not_found_handling": "single-page-application",
"binding": "ASSETS",
"run_worker_first": true
}

"assets": {
// "not_found_handling": "single-page-application",
"binding": "ASSETS",
"run_worker_first": true
}
But this will then ofc not work with SPA routing anymore...
lecstor
lecstor6d ago
I have the same issue. I'm using lucia to for social login in a working Pages app I'm trying to convert to workers with the new Vite plugin. For that we need the browser to be able to hit the worker directly for the login/callback paths but instead just get Not Found (on root route) for eg http://localhost:8788/auth/google/log-in It feels like this would require configuring specific routes that should go to the worker. I found a route property in wrangler config but that's not what we need. AI thought routing could go in the Vite plugin config but it seems it was just being delusional again. Definitely seems like it should be a wrangler thing as it's directly related to "not_found_handling". hmm.. https://github.com/cloudflare/workers-sdk/issues/8430#issuecomment-2798510465
I discovered the same thing when setting up OAuth (was very unintuitive). Ended up creating a separate worker to handle it.
lecstor
lecstor5d ago
I found it is possible to hack a fix into @Cloudflare/vite-plugin.. https://github.com/lecstor/workers-sdk/pull/1 yarn patch @cloudflare/vite-plugin @cloudflare/vite-plugin/dist/asset-workers/asset-worker.js
var ar = async (t14, e, n, r) => {
return (
(tr(n, Kt) &&
t14.headers.get("Sec-Fetch-Mode") === "navigate"
&& !new URL(t14.url).pathname.startsWith("/auth/")) // <----- hackedy hack
|| (n = { ...n, not_found_handling: "none" }),
!((await ir(t14, e, n, r)) instanceof ye)
);
};
var ar = async (t14, e, n, r) => {
return (
(tr(n, Kt) &&
t14.headers.get("Sec-Fetch-Mode") === "navigate"
&& !new URL(t14.url).pathname.startsWith("/auth/")) // <----- hackedy hack
|| (n = { ...n, not_found_handling: "none" }),
!((await ir(t14, e, n, r)) instanceof ye)
);
};
GitHub
route auth/* paths to the worker by lecstor · Pull Request #1 · l...
When using the &quot;not_found_handling&quot;: &quot;single-page-application&quot; configuration we can&#39;t implement OAuth flows that need to hit the worker directly. This ha...

Did you find this page helpful?