cater for self hosted draw.io

This commit is contained in:
2026-01-12 15:08:27 +11:00
parent c832d65fae
commit a08f7d8782
3 changed files with 10 additions and 1 deletions

View File

@@ -8,6 +8,7 @@ import (
"log"
"net/http"
"net/url"
"os"
"strings"
"time"
@@ -24,6 +25,8 @@ var diagramStore = struct {
data: make(map[string]string),
}
var drawioBaseURL = "https://app.diagrams.net"
var uploadTpl = template.Must(template.New("upload").Parse(`
<!doctype html>
<html lang="en">
@@ -133,6 +136,9 @@ type apiResponse struct {
}
func main() {
if v := strings.TrimSpace(os.Getenv("DRAWIO_BASE_URL")); v != "" {
drawioBaseURL = strings.TrimRight(v, "/")
}
mux := http.NewServeMux()
mux.HandleFunc("/", uploadHandler)
mux.HandleFunc("/convert", uploadConvertHandler)
@@ -330,7 +336,7 @@ func buildDiagramsNetURL(r *http.Request, id string) string {
}
base := fmt.Sprintf("%s://%s/diagram?id=%s", scheme, r.Host, url.QueryEscape(id))
// Request AWS library for custom shapes (e.g., aws4) to render correctly.
return "https://app.diagrams.net/?splash=0&ui=min&libs=aws4&url=" + url.QueryEscape(base)
return drawioBaseURL + "/?splash=0&ui=min&libs=aws4&url=" + url.QueryEscape(base)
}
func addCORS(w http.ResponseWriter) {