(ctx context.Context, cancel context.CancelFunc, pathPrefix string, counter *counter)
| 205 | } |
| 206 | |
| 207 | func (server *Server) setupHandlers(ctx context.Context, cancel context.CancelFunc, pathPrefix string, counter *counter) http.Handler { |
| 208 | staticFileHandler := http.FileServer( |
| 209 | &assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, Prefix: "static"}, |
| 210 | ) |
| 211 | |
| 212 | var siteMux = http.NewServeMux() |
| 213 | |
| 214 | siteMux.HandleFunc(pathPrefix, server.handleIndex) |
| 215 | siteMux.Handle(pathPrefix+"js/", http.StripPrefix(pathPrefix, staticFileHandler)) |
| 216 | siteMux.Handle(pathPrefix+"favicon.png", http.StripPrefix(pathPrefix, staticFileHandler)) |
| 217 | siteMux.Handle(pathPrefix+"css/", http.StripPrefix(pathPrefix, staticFileHandler)) |
| 218 | |
| 219 | siteMux.HandleFunc(pathPrefix+"auth_token.js", server.handleAuthToken) |
| 220 | siteMux.HandleFunc(pathPrefix+"config.js", server.handleConfig) |
| 221 | siteMux.HandleFunc("/api/kube-config", server.handleKubeConfigApi) |
| 222 | siteMux.HandleFunc("/api/kube-token", server.handleKubeTokenApi) |
| 223 | if len(os.Getenv("TERMINAL_PATH")) < 1 { |
| 224 | siteMux.HandleFunc("/", server.handleMain) |
| 225 | } |
| 226 | |
| 227 | if os.Getenv("PPROF_ENABLED") != "" { |
| 228 | siteMux.HandleFunc("/debug/pprof/", pprof.Index) |
| 229 | siteMux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) |
| 230 | siteMux.HandleFunc("/debug/pprof/profile", pprof.Profile) |
| 231 | siteMux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) |
| 232 | siteMux.HandleFunc("/debug/pprof/trace", pprof.Trace) |
| 233 | } |
| 234 | siteHandler := http.Handler(siteMux) |
| 235 | |
| 236 | if server.options.EnableBasicAuth { |
| 237 | log.Printf("Using Basic Authentication") |
| 238 | siteHandler = server.wrapBasicAuth(siteHandler, server.options.Credential) |
| 239 | } |
| 240 | |
| 241 | withGz := gziphandler.GzipHandler(server.wrapHeaders(siteHandler)) |
| 242 | siteHandler = server.wrapLogger(withGz) |
| 243 | |
| 244 | wsMux := http.NewServeMux() |
| 245 | wsMux.Handle("/", siteHandler) |
| 246 | wsMux.HandleFunc(pathPrefix+"ws", server.generateHandleWS(ctx, cancel, counter)) |
| 247 | siteHandler = http.Handler(wsMux) |
| 248 | |
| 249 | return siteHandler |
| 250 | } |
| 251 | |
| 252 | func (server *Server) setupHTTPServer(handler http.Handler) (*http.Server, error) { |
| 253 | srv := &http.Server{ |
no test coverage detected