From 33e23b69bdc8617225f4411ef9bb8623d8cae45a Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Sun, 21 Jul 2024 15:43:54 +0200 Subject: [PATCH] redirect all non-matched urls to the docs. --- Dockerfile | 8 +++----- cmd/converge/server.go | 8 +++++++- static/index.html | 12 ++++++------ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index af2aac3..3892211 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,14 +6,12 @@ COPY . /opt/converge/ WORKDIR /opt/converge RUN go mod download COPY . /opt/converge/ -#RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o main . RUN go build -ldflags "-linkmode 'external' -extldflags '-static'" -o bin ./cmd/... -#RUN mkdir -p /opt/converge/downloads/ FROM scratch COPY --from=builder /opt/converge/bin/converge /opt/converge/bin/ -COPY --from=builder /opt/converge/bin/agent /opt/converge/bin/tcptows /opt/converge/downloads/ -COPY --from=builder /opt/converge/static/ /opt/converge/downloads/ +COPY --from=builder /opt/converge/bin/agent /opt/converge/bin/tcptows /opt/converge/docs/ +COPY --from=builder /opt/converge/static/ /opt/converge/docs/ -ENTRYPOINT ["/opt/converge/bin/converge", "/opt/converge/downloads" ] +ENTRYPOINT ["/opt/converge/bin/converge", "/opt/converge/docs" ] diff --git a/cmd/converge/server.go b/cmd/converge/server.go index 44a0d3e..4db9826 100644 --- a/cmd/converge/server.go +++ b/cmd/converge/server.go @@ -20,6 +20,11 @@ func parsePublicId(path string) (publicId string, _ error) { return matches[1], nil } +func catchAllHandler(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, "/docs", http.StatusFound) + return +} + func main() { downloadDir := "downloads" @@ -60,7 +65,8 @@ func main() { http.HandleFunc("/agent/", registrationService.Handle) http.HandleFunc("/client/", clientService.Handle) - http.Handle("/downloads/", http.StripPrefix("/downloads/", http.FileServer(http.Dir(downloadDir)))) + http.Handle("/docs/", http.StripPrefix("/docs/", http.FileServer(http.Dir(downloadDir)))) + http.HandleFunc("/", catchAllHandler) // Start HTTP server fmt.Println("Rendez-vous server listening on :8000") diff --git a/static/index.html b/static/index.html index 503537b..306dad7 100644 --- a/static/index.html +++ b/static/index.html @@ -23,12 +23,12 @@

     # for HTTP hosted server
-    curl http://HOSTPORT/downloads/agent > agent
+    curl http://HOSTPORT/docs/agent > agent
      ./agent ws://HOST:PORT/agent/ID
     chmod 755 agent
 
     # for HTTPS hosted server
-     curl https://HOSTPORT/downloads/agent > agent
+     curl https://HOSTPORT/docs/agent > agent
      ./agent wss://HOST:PORT/agent/ID
     chmod 755 agent
 
@@ -51,12 +51,12 @@
     # for HTTP hosted server
-    curl http://HOST:PORT/downloads/wstotcp > wstotcp
+    curl http://HOST:PORT/docs/wstotcp > wstotcp
     chmod 755 wstotcp
     ./wstotcp 10000 ws://HOST:PORT/client/ID
 
     # for HTTPS hosted server
-    curl https://HOST:PORT/downloads/wstotcp > wstotcp
+    curl https://HOST:PORT/docs/wstotcp > wstotcp
     chmod 755 wstotcp
     ./wstotcp 10000 wss://HOST:PORT/client/ID
 
@@ -81,9 +81,9 @@

Downloads