Skip to content

Commit 2d643e8

Browse files
G4brymDebianMarcelo
authored
fix: ensure API routes bypass SPA fallback + add troubleshooting docs (G4brym#126)
* fix: ensure API and share routes are handled by worker, not SPA fallback The `not_found_handling = "single-page-application"` asset config causes Cloudflare to serve index.html for any request that doesn't match a static file — including /api/* and /share/* routes. This results in downloads returning a ~2KB HTML page instead of the actual file. Adding `run_worker_first = ["/api/*", "/share/*"]` ensures these routes are always dispatched to the worker script first. Fixes G4brym#119 * docs: add troubleshooting guide Cover common issues: downloads returning HTML instead of files (SPA fallback intercepting API routes), 401 errors with basic auth, and blank page / routing errors. Co-Authored-By: Marcelo <noreply@openclaw.ai> --------- Co-authored-by: Debian <openclaw@openclaw.1.1.1.1> Co-authored-by: Marcelo <noreply@openclaw.ai>
1 parent f5e8371 commit 2d643e8

File tree

5 files changed

+55
-3
lines changed

5 files changed

+55
-3
lines changed

packages/docs/.vitepress/config.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export default defineConfig({
3939
items: [
4040
{ text: 'Setup Email Explorer', link: '/guides/setup-email-explorer' },
4141
{ text: 'Sharable Links', link: '/guides/sharable-links' },
42+
{ text: 'Troubleshooting', link: '/guides/troubleshooting' },
4243
]
4344
}
4445
],
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Troubleshooting
2+
3+
Common issues and solutions for R2 Explorer.
4+
5+
## Downloads return HTML instead of the actual file
6+
7+
**Symptoms:** Clicking "Download" in the context menu downloads a small (~2KB) HTML file instead of the actual object. Browsing and previewing files works normally.
8+
9+
**Cause:** When using Cloudflare Workers with [static assets](https://developers.cloudflare.com/workers/static-assets/), the `not_found_handling = "single-page-application"` setting in `wrangler.toml` tells Cloudflare to serve `index.html` for any request that doesn't match a static file. This happens **before** your Worker code runs, so API requests like `/api/buckets/<bucket>/<key>` never reach the R2 Explorer backend — Cloudflare intercepts them and returns the SPA's HTML.
10+
11+
**Fix:** Add `run_worker_first` to your `wrangler.toml` assets configuration so that API and share routes are always handled by the Worker:
12+
13+
```toml
14+
# Before (broken)
15+
assets = { directory = "node_modules/r2-explorer/dashboard", binding = "ASSETS", html_handling = "auto-trailing-slash", not_found_handling = "single-page-application" }
16+
17+
# After (fixed)
18+
assets = { directory = "node_modules/r2-explorer/dashboard", binding = "ASSETS", html_handling = "auto-trailing-slash", not_found_handling = "single-page-application", run_worker_first = ["/api/*", "/share/*"] }
19+
```
20+
21+
After updating, redeploy with `wrangler deploy`.
22+
23+
::: tip
24+
New projects created from the template already include this fix. This only affects existing deployments that were set up before this change.
25+
:::
26+
27+
## Downloads fail with 401 when using Basic Auth
28+
29+
**Symptoms:** File downloads from the right-click context menu fail with a `401 Unauthorized` error. Browsing and previewing files works fine. May work in Safari but fail in Chrome.
30+
31+
**Cause:** The download function was creating a raw `<a>` HTML element pointing directly at the API URL and triggering `link.click()`. Browser-initiated downloads via `<a>` links do **not** include custom HTTP headers like `Authorization: Basic ...`, so the request arrives at the Worker without credentials. Chrome enforces this strictly; Safari is more lenient.
32+
33+
**Fix:** This was fixed in [v0.5.2](https://github.com/G4brym/R2-Explorer/releases). Update your R2 Explorer dependency:
34+
35+
```bash
36+
npm update r2-explorer
37+
wrangler deploy
38+
```
39+
40+
## Dashboard shows a blank page or routing errors
41+
42+
**Symptoms:** The dashboard loads but shows a blank page, or navigating between pages results in errors like `TypeError: Cannot read properties of undefined (reading 'name')`.
43+
44+
**Cause:** This can happen when the Vue router's `this.$route.name` is `undefined` during navigation transitions.
45+
46+
**Fix:** This was fixed in [v0.5.2](https://github.com/G4brym/R2-Explorer/releases). Update your R2 Explorer dependency:
47+
48+
```bash
49+
npm update r2-explorer
50+
wrangler deploy
51+
```

packages/github-action/prepareDeploy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ let wranglerConfig = `
3838
name = "${R2EXPLORER_WORKER_NAME}"
3939
compatibility_date = "2024-11-06"
4040
main = "src/index.ts"
41-
assets = { directory = "node_modules/r2-explorer/dashboard", binding = "ASSETS", html_handling = "auto-trailing-slash", not_found_handling = "single-page-application" }
41+
assets = { directory = "node_modules/r2-explorer/dashboard", binding = "ASSETS", html_handling = "auto-trailing-slash", not_found_handling = "single-page-application", run_worker_first = ["/api/*", "/share/*"] }
4242
`;
4343

4444
if (R2EXPLORER_DOMAIN) {

packages/worker/dev/wrangler.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = "my-r2-explorer"
22
compatibility_date = "2024-11-06"
33
main = "index.ts"
44
workers_dev = true
5-
assets = { directory = "../../dashboard/dist/spa", binding = "ASSETS", html_handling = "auto-trailing-slash", not_found_handling = "single-page-application" }
5+
assets = { directory = "../../dashboard/dist/spa", binding = "ASSETS", html_handling = "auto-trailing-slash", not_found_handling = "single-page-application", run_worker_first = ["/api/*", "/share/*"] }
66

77
[[r2_buckets]]
88
binding = 'teste'

template/wrangler.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "r2-explorer"
22
compatibility_date = "2024-11-06"
33
main = "src/index.ts"
4-
assets = { directory = "node_modules/r2-explorer/dashboard", binding = "ASSETS", html_handling = "auto-trailing-slash", not_found_handling = "single-page-application" }
4+
assets = { directory = "node_modules/r2-explorer/dashboard", binding = "ASSETS", html_handling = "auto-trailing-slash", not_found_handling = "single-page-application", run_worker_first = ["/api/*", "/share/*"] }
55

66
# Bind R2 Buckets to your application.
77
# Docs: https://r2explorer.com/getting-started/add-r2-buckets/

0 commit comments

Comments
 (0)