Skip to content

Commit 475178e

Browse files
committed
fix: Update Caddyfile with working route-based path rewriting
- Use route directive for proper request matching - Fix redirect matchers with path_regexp for exact matching - All tests now passing: ✅ Root redirect (/ → /codimd/) ✅ Path redirect (/codimd → /codimd/) ✅ Main app accessible at /codimd/ ✅ Static assets working ✅ Build assets working ✅ Path stripping via uri strip_prefix ✅ X-Forwarded-Prefix header passed to app
1 parent aac0abc commit 475178e

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

Caddyfile.experiment

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,43 @@
88
}
99

1010
:8080 {
11-
# Handle Socket.IO separately - rewrite path for WebSocket upgrade
12-
handle /codimd/socket.io/* {
11+
# Enable logging for debugging
12+
log {
13+
output stdout
14+
level INFO
15+
format console
16+
}
17+
18+
# Route order matters! Use route directive for proper matching
19+
20+
# 1. Redirect exact /codimd to /codimd/
21+
route {
22+
@codimd_exact path_regexp ^/codimd$
23+
redir @codimd_exact /codimd/ 301
24+
}
25+
26+
# 2. Redirect root to /codimd/
27+
route {
28+
@root path_regexp ^/$
29+
redir @root /codimd/ 301
30+
}
31+
32+
# 3. Handle Socket.IO - rewrite path for WebSocket upgrade
33+
route /codimd/socket.io/* {
1334
uri strip_prefix /codimd
1435
reverse_proxy localhost:3000 {
15-
# WebSocket support
16-
header_up X-Forwarded-For {remote_host}
17-
header_up X-Forwarded-Proto {scheme}
18-
header_up X-Forwarded-Host {host}
1936
header_up X-Forwarded-Prefix /codimd
2037
}
2138
}
2239

23-
# Handle all /codimd/* requests
24-
handle /codimd/* {
40+
# 4. Handle all other /codimd/* requests
41+
route /codimd/* {
2542
# Strip /codimd prefix before forwarding
2643
uri strip_prefix /codimd
2744

2845
# Reverse proxy to app running at root
2946
reverse_proxy localhost:3000 {
30-
# Pass headers for proxy awareness
31-
header_up X-Forwarded-For {remote_host}
32-
header_up X-Forwarded-Proto {scheme}
33-
header_up X-Forwarded-Host {host}
3447
header_up X-Forwarded-Prefix /codimd
3548
}
3649
}
37-
38-
# Handle /codimd without trailing slash
39-
handle_path /codimd {
40-
redir /codimd/ 301
41-
}
42-
43-
# Redirect root to /codimd/
44-
handle / {
45-
redir /codimd/ 301
46-
}
47-
48-
# Enable logging for debugging
49-
log {
50-
output stdout
51-
level DEBUG
52-
format console
53-
}
5450
}

0 commit comments

Comments
 (0)