diff --git a/.devcontainer.json b/.devcontainer.json index 58f2f84..4152548 100644 --- a/.devcontainer.json +++ b/.devcontainer.json @@ -7,19 +7,21 @@ "containerEnv": { "DEVELOPMENT": "True" }, - "settings": { - "terminal.integrated.shell.linux": "/bin/bash", - "go.useGoProxyToCheckForToolUpdates": false, - "go.useLanguageServer": true, - "go.gopath": "/go", - "go.goroot": "/usr/local/go", - "go.toolsGopath": "/go/bin", - "go.lintTool":"golangci-lint", - "go.lintFlags": [ - "--fast" - ] - }, - "extensions": [ - "golang.Go" - ] + "customizations": { + "vscode": { + "settings": { + "terminal.integrated.shell.linux": "/bin/bash", + "go.useGoProxyToCheckForToolUpdates": false, + "go.useLanguageServer": true, + "go.gopath": "/go", + "go.goroot": "/usr/local/go", + "go.toolsGopath": "/go/bin", + "go.lintTool":"golangci-lint", + "go.lintFlags": [ + "--fast" + ] + }, + "extensions": ["golang.Go"] + } + } } diff --git a/http.go b/http.go index 5f93025..b651758 100644 --- a/http.go +++ b/http.go @@ -57,7 +57,13 @@ func httpSupervisorProxy(w http.ResponseWriter, r *http.Request) { log.Printf("Proxy request: %s", r.URL.Path) // Base Supervisor URL - u, err := url.Parse("http://supervisor/") + supervisorHost := "supervisor" + + if development && os.Getenv("SUPERVISOR_HOST") != "" { + supervisorHost = os.Getenv("SUPERVISOR_HOST") + } + + u, err := url.Parse("http://" + supervisorHost + "/") if err != nil { // Handle error in parsing URL w.Write([]byte(err.Error())) @@ -100,6 +106,14 @@ func httpSupervisorProxy(w http.ResponseWriter, r *http.Request) { // Add authorization header r.Header.Add("Authorization", "Bearer "+os.Getenv("SUPERVISOR_TOKEN")) + if cleanPath == "/logs" { + // for logs download add text/plain headers + r.Header.Add("Accept", "text/plain") + } else if cleanPath == "/logs/follow" { + // Set FlushInterval to enable streaming + proxy.FlushInterval = -1 + } + // Forward the request proxy.ServeHTTP(w, r) } diff --git a/main.go b/main.go index bc0da19..d0aa55b 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,9 @@ var development bool func main() { development = (os.Getenv("DEVELOPMENT") == "True") - if development { + if development && os.Getenv("FRONTEND_PATH") != "" { + wwwRoot = os.Getenv("FRONTEND_PATH") + "/landing-page/dist/" + } else if development { wwwRoot = "./rootfs/usr/share/www/" } else { wwwRoot = "/usr/share/www/" @@ -27,6 +29,8 @@ func main() { http.HandleFunc("/api/", httpUnauthorized) http.HandleFunc("/auth/token", httpBad) http.HandleFunc("/observer/logs", httpLogs) + http.HandleFunc("/supervisor/supervisor/logs", httpSupervisorProxy) + http.HandleFunc("/supervisor/supervisor/logs/follow", httpSupervisorProxy) http.HandleFunc("/supervisor/resolution/", httpSupervisorProxy) http.HandleFunc("/supervisor/network/", httpSupervisorProxy)