This commit is contained in:
2026-01-12 16:11:15 +11:00
parent 31bec02c75
commit b60256f61a

View File

@@ -1,9 +1,6 @@
package main
import (
"bytes"
"compress/flate"
"encoding/base64"
"encoding/json"
"fmt"
"html/template"
@@ -342,18 +339,9 @@ func buildDiagramsNetURL(r *http.Request, id string, xml string) string {
scheme = "https"
}
base := fmt.Sprintf("%s://%s/diagram?id=%s", scheme, r.Host, url.QueryEscape(id))
// For self-hosted instances that insist on proxying, avoid the remote fetch entirely by providing a compressed data
// URI in the fragment. Fragment data is not sent over the network, so this stays client-side and avoids proxy 404s.
target := base
if xml != "" {
var buf bytes.Buffer
w, _ := flate.NewWriter(&buf, flate.BestCompression)
_, _ = w.Write([]byte(xml))
_ = w.Close()
compressed := base64.StdEncoding.EncodeToString(buf.Bytes())
target = "data:application/octet-stream;base64," + compressed
}
return fmt.Sprintf("%s/?splash=0&ui=min&libs=aws4#U%s", drawioBaseURL, target)
encoded := url.QueryEscape(base)
// Ask draw.io not to proxy (`proxy=0`) so it fetches directly (CORS headers are already set on /diagram).
return fmt.Sprintf("%s/?splash=0&ui=min&libs=aws4&proxy=0&url=%s", drawioBaseURL, encoded)
}
func addCORS(w http.ResponseWriter) {