From 5702d9fd74d19cc1b8ce9498d4e8bc448da9768e Mon Sep 17 00:00:00 2001 From: Julian Hurst Date: Wed, 2 Apr 2025 17:39:43 +0200 Subject: Support a proxy prefix via BOX_PROXY_PREFIX --- main.go | 8 +++++++- templates/index.html | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 2223a4c..0556242 100644 --- a/main.go +++ b/main.go @@ -38,7 +38,13 @@ func serve(w http.ResponseWriter, token []byte, views ...string) { if err != nil { log.Fatal(err) } - if err := t.Execute(w, token != nil); err != nil { + if err := t.Execute(w, struct { + Token bool + ProxyPrefix string + }{ + Token: token != nil, + ProxyPrefix: os.Getenv("BOX_PROXY_PREFIX"), + }); err != nil { log.Fatal(err) } } diff --git a/templates/index.html b/templates/index.html index 8bb0e38..75f504c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -36,7 +36,7 @@ resourceId = xhr.getResponseHeader("X-Resource-ID"); } } - xhr.open("POST", "/upload", true); + xhr.open("POST", "{{.ProxyPrefix}}/upload", true); xhr.setRequestHeader("X-Token", token); ldot = f.name.lastIndexOf("."); if (ldot > -1) { @@ -66,7 +66,7 @@ This ID can then be used to get the file by sending a GET request to /[resourceI If enabled on the server, the resource can be deleted by sending a DELETE request to /[resourceID]. Again if a token has been set on the server, use a X-Token header when sending the request. - {{ if . }} + {{ if .Token }} {{end}}

-- cgit v1.2.3