@@ -12,16 +12,23 @@ import (
12
12
"strings"
13
13
)
14
14
15
- var regexASCII = regexp .MustCompile (`\[\d+m` )
15
+ var regexASCII = regexp .MustCompile (`\x1b\ [\d+m` )
16
16
17
17
func httpIndex (w http.ResponseWriter , r * http.Request ) {
18
18
if r .URL .Path != "/" && r .URL .Path != "/auth/authorize" {
19
19
http .Error (w , http .StatusText (http .StatusNotFound ), http .StatusNotFound )
20
20
return
21
21
}
22
- data , _ := os .ReadFile (wwwRoot + "/index.html" )
22
+ data , err := os .ReadFile (wwwRoot + "/index.html" )
23
+ if err != nil {
24
+ log .Printf ("failed to read index.html: %v" , err )
25
+ http .Error (w , "Internal Server Error" , http .StatusInternalServerError )
26
+ return
27
+ }
23
28
24
- w .Write (data )
29
+ if _ , err := w .Write (data ); err != nil {
30
+ log .Printf ("failed to write response: %v" , err )
31
+ }
25
32
}
26
33
27
34
func httpUnauthorized (w http.ResponseWriter , r * http.Request ) {
@@ -40,7 +47,11 @@ func httpLogs(w http.ResponseWriter, r *http.Request) {
40
47
http .Error (w , http .StatusText (http .StatusInternalServerError ), http .StatusInternalServerError )
41
48
return
42
49
}
43
- defer response .Body .Close ()
50
+ defer func () {
51
+ if err := response .Body .Close (); err != nil {
52
+ log .Printf ("error closing response body: %v" , err )
53
+ }
54
+ }()
44
55
45
56
data , err := io .ReadAll (response .Body )
46
57
if err != nil {
@@ -50,7 +61,9 @@ func httpLogs(w http.ResponseWriter, r *http.Request) {
50
61
}
51
62
52
63
logs := regexASCII .ReplaceAllLiteralString (string (data ), "" )
53
- w .Write ([]byte (logs ))
64
+ if _ , err := w .Write ([]byte (logs )); err != nil {
65
+ log .Printf ("failed to write response: %v" , err )
66
+ }
54
67
}
55
68
56
69
func httpSupervisorProxy (w http.ResponseWriter , r * http.Request ) {
@@ -65,8 +78,7 @@ func httpSupervisorProxy(w http.ResponseWriter, r *http.Request) {
65
78
66
79
u , err := url .Parse ("http://" + supervisorHost + "/" )
67
80
if err != nil {
68
- // Handle error in parsing URL
69
- w .Write ([]byte (err .Error ()))
81
+ http .Error (w , "Internal Server Error: " + err .Error (), http .StatusInternalServerError )
70
82
return
71
83
}
72
84
@@ -106,10 +118,11 @@ func httpSupervisorProxy(w http.ResponseWriter, r *http.Request) {
106
118
// Add authorization header
107
119
r .Header .Add ("Authorization" , "Bearer " + os .Getenv ("SUPERVISOR_TOKEN" ))
108
120
109
- if cleanPath == "/logs" {
121
+ switch cleanPath {
122
+ case "/logs" :
110
123
// for logs download add text/plain headers
111
124
r .Header .Add ("Accept" , "text/plain" )
112
- } else if cleanPath == "/logs/follow" {
125
+ case "/logs/follow" :
113
126
// Set FlushInterval to enable streaming
114
127
proxy .FlushInterval = - 1
115
128
}
0 commit comments