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

@@ -27,6 +27,7 @@ The HTTP server exposes a simple REST endpoint plus docs.
- Swagger UI: `http://localhost:8080/swagger`
- OpenAPI spec: `http://localhost:8080/openapi.json`
- diagrams.net host override: set environment variable `DRAWIO_BASE_URL` (defaults to `https://app.diagrams.net`)
### Endpoint
`POST /api/convert`

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) {

View File

@@ -5,4 +5,6 @@ services:
build: .
ports:
- "8080:8080"
environment:
- DRAWIO_BASE_URL=${DRAWIO_BASE_URL:-https://app.diagrams.net}
restart: unless-stopped