Spaces:
Running
Running
Remove root /api and /assets hijacking in Caddyfile and use pure relative paths for opencode-router
Browse files- config/Caddyfile.example +3 -12
- entrypoint.sh +8 -5
- services/20-opencode-router.sh +7 -4
config/Caddyfile.example
CHANGED
|
@@ -41,8 +41,8 @@
|
|
| 41 |
}
|
| 42 |
|
| 43 |
# 4. opencode-router (/opencode/* -> 127.0.0.1:8787)
|
| 44 |
-
# Strip prefix so /opencode/
|
| 45 |
-
#
|
| 46 |
@opencode_noslash path /opencode
|
| 47 |
redir @opencode_noslash /opencode/ 308
|
| 48 |
|
|
@@ -50,16 +50,7 @@
|
|
| 50 |
reverse_proxy 127.0.0.1:8787
|
| 51 |
}
|
| 52 |
|
| 53 |
-
#
|
| 54 |
-
handle /api/* {
|
| 55 |
-
reverse_proxy 127.0.0.1:8648
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
handle /assets/* {
|
| 59 |
-
reverse_proxy 127.0.0.1:8787
|
| 60 |
-
}
|
| 61 |
-
|
| 62 |
-
# Route /v1 to Hermes API server or opencode-router
|
| 63 |
handle /v1/* {
|
| 64 |
reverse_proxy 127.0.0.1:8787
|
| 65 |
}
|
|
|
|
| 41 |
}
|
| 42 |
|
| 43 |
# 4. opencode-router (/opencode/* -> 127.0.0.1:8787)
|
| 44 |
+
# Strip prefix so everything under /opencode/ (index.html, assets, /api, /v1)
|
| 45 |
+
# routes strictly through /opencode without polluting the root domain.
|
| 46 |
@opencode_noslash path /opencode
|
| 47 |
redir @opencode_noslash /opencode/ 308
|
| 48 |
|
|
|
|
| 50 |
reverse_proxy 127.0.0.1:8787
|
| 51 |
}
|
| 52 |
|
| 53 |
+
# Route root /v1 to opencode-router for standard OpenAI API clients
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
handle /v1/* {
|
| 55 |
reverse_proxy 127.0.0.1:8787
|
| 56 |
}
|
entrypoint.sh
CHANGED
|
@@ -47,17 +47,20 @@ chmod 600 /tmp/.env
|
|
| 47 |
# Clean legacy logs/tmp from previous iterations
|
| 48 |
rm -rf /data/logs /data/tmp /data/.cache /data/openclaw /data/script/codeman 2>/dev/null || true
|
| 49 |
|
| 50 |
-
# Deploy opencode-router
|
| 51 |
mkdir -p /data/script/opencode-router
|
| 52 |
cp -rn /opt/opencode-router/* /data/script/opencode-router/ 2>/dev/null || true
|
| 53 |
chmod +x /data/script/opencode-router/opencode-router 2>/dev/null || true
|
| 54 |
|
| 55 |
-
#
|
| 56 |
INDEX_HTML="/data/script/opencode-router/public/index.html"
|
| 57 |
if [ -f "$INDEX_HTML" ]; then
|
| 58 |
-
sed -i 's
|
| 59 |
-
sed -i 's|<head>
|
| 60 |
-
sed -i 's|
|
|
|
|
|
|
|
|
|
|
| 61 |
fi
|
| 62 |
|
| 63 |
# Redirect caches & logs to /tmp so S3 doesn't accumulate garbage
|
|
|
|
| 47 |
# Clean legacy logs/tmp from previous iterations
|
| 48 |
rm -rf /data/logs /data/tmp /data/.cache /data/openclaw /data/script/codeman 2>/dev/null || true
|
| 49 |
|
| 50 |
+
# Deploy clean opencode-router with assets and public UI into /data/script/opencode-router
|
| 51 |
mkdir -p /data/script/opencode-router
|
| 52 |
cp -rn /opt/opencode-router/* /data/script/opencode-router/ 2>/dev/null || true
|
| 53 |
chmod +x /data/script/opencode-router/opencode-router 2>/dev/null || true
|
| 54 |
|
| 55 |
+
# Copy clean index.html exactly from Hermes distribution with relative paths
|
| 56 |
INDEX_HTML="/data/script/opencode-router/public/index.html"
|
| 57 |
if [ -f "$INDEX_HTML" ]; then
|
| 58 |
+
sed -i 's|const basePath = window.location.pathname.replace(/\\/+$/, "");||g' "$INDEX_HTML" 2>/dev/null || true
|
| 59 |
+
sed -i 's|<head><base href="/opencode/">|<head>|g' "$INDEX_HTML" 2>/dev/null || true
|
| 60 |
+
sed -i 's|href="/assets/|href="assets/|g' "$INDEX_HTML" 2>/dev/null || true
|
| 61 |
+
sed -i 's|src="/assets/|src="assets/|g' "$INDEX_HTML" 2>/dev/null || true
|
| 62 |
+
sed -i 's|function api(path,|const basePath = window.location.pathname.replace(/\\/+$/, ""); function api(path,|g' "$INDEX_HTML" 2>/dev/null || true
|
| 63 |
+
sed -i 's|return fetch(path,|const targetPath = basePath + (path.startsWith("/") ? path : "/" + path); return fetch(targetPath,|g' "$INDEX_HTML" 2>/dev/null || true
|
| 64 |
fi
|
| 65 |
|
| 66 |
# Redirect caches & logs to /tmp so S3 doesn't accumulate garbage
|
services/20-opencode-router.sh
CHANGED
|
@@ -7,12 +7,15 @@ LOG="/tmp/logs/opencode-router.log"
|
|
| 7 |
|
| 8 |
cp -rn /opt/opencode-router/* "$DIR/" 2>/dev/null || true
|
| 9 |
|
| 10 |
-
#
|
| 11 |
INDEX_HTML="$DIR/public/index.html"
|
| 12 |
if [ -f "$INDEX_HTML" ]; then
|
| 13 |
-
sed -i 's
|
| 14 |
-
sed -i 's|<head>
|
| 15 |
-
sed -i 's|
|
|
|
|
|
|
|
|
|
|
| 16 |
fi
|
| 17 |
|
| 18 |
# Do NOT overwrite existing config on /data; seed default only if missing
|
|
|
|
| 7 |
|
| 8 |
cp -rn /opt/opencode-router/* "$DIR/" 2>/dev/null || true
|
| 9 |
|
| 10 |
+
# Ensure relative path resolution in public/index.html so /opencode doesn't hijack root /assets or /api
|
| 11 |
INDEX_HTML="$DIR/public/index.html"
|
| 12 |
if [ -f "$INDEX_HTML" ]; then
|
| 13 |
+
sed -i 's|const basePath = window.location.pathname.replace(/\\/+$/, "");||g' "$INDEX_HTML" 2>/dev/null || true
|
| 14 |
+
sed -i 's|<head><base href="/opencode/">|<head>|g' "$INDEX_HTML" 2>/dev/null || true
|
| 15 |
+
sed -i 's|href="/assets/|href="assets/|g' "$INDEX_HTML" 2>/dev/null || true
|
| 16 |
+
sed -i 's|src="/assets/|src="assets/|g' "$INDEX_HTML" 2>/dev/null || true
|
| 17 |
+
sed -i 's|function api(path,|const basePath = window.location.pathname.replace(/\\/+$/, ""); function api(path,|g' "$INDEX_HTML" 2>/dev/null || true
|
| 18 |
+
sed -i 's|return fetch(path,|const targetPath = basePath + (path.startsWith("/") ? path : "/" + path); return fetch(targetPath,|g' "$INDEX_HTML" 2>/dev/null || true
|
| 19 |
fi
|
| 20 |
|
| 21 |
# Do NOT overwrite existing config on /data; seed default only if missing
|