Direct access to worker endpoints from the browser

How do i access the worker endpoints directly from the browser when using the vite plugin? Setting the following doesn't solve it
"run_worker_first": [
"/api/*",
"!/api/docs/*"
]
"run_worker_first": [
"/api/*",
"!/api/docs/*"
]
Accessing /api directly still shows the vite frontend.
6 Replies
i40west
i40west5mo ago
What comes immediately to mind is that /api doesn't match /api/*. (Can you access things under /api like /api/foo?) If you want /api to work try using "/api*".
Noobie☺
Noobie☺OP5mo ago
Thanks for pointing out /api*. i only had / under api route. Now anything under /api is directly accessible through the browser(tried adding /health to the api route)
Noobie☺
Noobie☺OP5mo ago
what about subdomain routing based on hostnames in hono? i tried accessing it through the terminal and this is what i get in the second image The 3rd image is code for CdnMiddleware handler
No description
No description
No description
i40west
i40west5mo ago
You're returning the static asset. If the route you're hitting matches a static asset but you want the worker to respond you need run_worker_first.
Noobie☺
Noobie☺OP5mo ago
i already use run_worker_first for /api so care to explain how to proceed for dynamic cdn subdomains(cdnmiddleware was just a testing phase)? i have a handler for various subdomains for the main app. setting run_worker_first to true gives me a 404 for the vite client
No description
i40west
i40west5mo ago
A route can match a static asset or not. If you want a route that matches a static asset to hit the worker, you need run_worker_first. If you then decide that you don't want the worker to handle it, perhaps based on the hostname, you can hand back to the static asset handling with env.ASSETS.fetch().

Did you find this page helpful?