cater for self hosted draw.io
This commit is contained in:
@@ -27,6 +27,7 @@ The HTTP server exposes a simple REST endpoint plus docs.
|
|||||||
|
|
||||||
- Swagger UI: `http://localhost:8080/swagger`
|
- Swagger UI: `http://localhost:8080/swagger`
|
||||||
- OpenAPI spec: `http://localhost:8080/openapi.json`
|
- OpenAPI spec: `http://localhost:8080/openapi.json`
|
||||||
|
- diagrams.net host override: set environment variable `DRAWIO_BASE_URL` (defaults to `https://app.diagrams.net`)
|
||||||
|
|
||||||
### Endpoint
|
### Endpoint
|
||||||
`POST /api/convert`
|
`POST /api/convert`
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -24,6 +25,8 @@ var diagramStore = struct {
|
|||||||
data: make(map[string]string),
|
data: make(map[string]string),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var drawioBaseURL = "https://app.diagrams.net"
|
||||||
|
|
||||||
var uploadTpl = template.Must(template.New("upload").Parse(`
|
var uploadTpl = template.Must(template.New("upload").Parse(`
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
@@ -133,6 +136,9 @@ type apiResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
if v := strings.TrimSpace(os.Getenv("DRAWIO_BASE_URL")); v != "" {
|
||||||
|
drawioBaseURL = strings.TrimRight(v, "/")
|
||||||
|
}
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("/", uploadHandler)
|
mux.HandleFunc("/", uploadHandler)
|
||||||
mux.HandleFunc("/convert", uploadConvertHandler)
|
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))
|
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.
|
// 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) {
|
func addCORS(w http.ResponseWriter) {
|
||||||
|
|||||||
@@ -5,4 +5,6 @@ services:
|
|||||||
build: .
|
build: .
|
||||||
ports:
|
ports:
|
||||||
- "8080:8080"
|
- "8080:8080"
|
||||||
|
environment:
|
||||||
|
- DRAWIO_BASE_URL=${DRAWIO_BASE_URL:-https://app.diagrams.net}
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
Reference in New Issue
Block a user