fix: serve map.js as embedded static file instead of inlining

index.html was loading map.js via <script src="map.js"> but the file
was not embedded or served, causing a 404 that left loadMapAsset
undefined → connectOrchWs() threw before creating the WebSocket →
status stayed at "Connecting…" forever.

- //go:embed now includes static/map.js alongside static/index.html
- Added /miniapp/map.js route served from embedded FS
- Updated script src to absolute path /miniapp/map.js
- map.js stays as a readable standalone file (not inlined)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
dj-oyu 2026-02-25 04:55:40 +09:00
parent 9649fba2da
commit e40efb7dd7
2 changed files with 13 additions and 2 deletions

View file

@ -10,7 +10,7 @@ import (
"github.com/sipeed/picoclaw/pkg/orch"
)
//go:embed static/index.html
//go:embed static/index.html static/map.js
var staticFS embed.FS
// Handler serves the Mini App HTML and API endpoints.
@ -74,6 +74,7 @@ func (h *Handler) RegisterRoutes(mux *http.ServeMux) {
mux.HandleFunc("/miniapp/api/logs/snapshot", h.requireAuth(h.apiLogsSnapshot))
mux.HandleFunc("/miniapp/api/logs/snapshot/", h.requireAuth(h.apiLogsSnapshotDownload))
mux.HandleFunc("/miniapp/api/orchestration/ws", h.requireAuth(h.wsOrchestration))
mux.HandleFunc("/miniapp/map.js", h.serveMapJS)
mux.HandleFunc("/miniapp/dev/console", h.apiDevConsole)
mux.HandleFunc("/miniapp/dev/", h.serveDevProxy)
}
@ -87,3 +88,13 @@ func (h *Handler) serveIndex(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Write(data)
}
func (h *Handler) serveMapJS(w http.ResponseWriter, r *http.Request) {
data, err := staticFS.ReadFile("static/map.js")
if err != nil {
http.Error(w, "not found", http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "application/javascript; charset=utf-8")
w.Write(data)
}

View file

@ -791,7 +791,7 @@
</style>
<link href="https://fonts.googleapis.com/css2?family=Silkscreen&display=swap" rel="stylesheet">
<script src="map.js"></script>
<script src="/miniapp/map.js"></script>
</head>
<body>