func startHTTPServer()

in src/httpserver.go [60:99]


func startHTTPServer(streamingProxyAddr string, apihost string) {
	httpPort := os.Getenv("HTTP_SERVER_PORT")
	if httpPort == "" {
		httpPort = "80"
	}

	router := http.NewServeMux()

	router.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Streamer proxy running"))
	})

	router.HandleFunc("GET /web/{ns}/{action}", handlers.WebActionStreamHandler(streamingProxyAddr, apihost))
	router.HandleFunc("GET /web/{ns}/{pkg}/{action}", handlers.WebActionStreamHandler(streamingProxyAddr, apihost))
	router.HandleFunc("GET /action/{ns}/{action}", handlers.ActionStreamHandler(streamingProxyAddr, apihost))
	router.HandleFunc("GET /action/{ns}/{pkg}/{action}", handlers.ActionStreamHandler(streamingProxyAddr, apihost))

	router.HandleFunc("POST /web/{ns}/{action}", handlers.WebActionStreamHandler(streamingProxyAddr, apihost))
	router.HandleFunc("POST /web/{ns}/{pkg}/{action}", handlers.WebActionStreamHandler(streamingProxyAddr, apihost))
	router.HandleFunc("POST /action/{ns}/{action}", handlers.ActionStreamHandler(streamingProxyAddr, apihost))
	router.HandleFunc("POST /action/{ns}/{pkg}/{action}", handlers.ActionStreamHandler(streamingProxyAddr, apihost))

	corsEnabled := os.Getenv("CORS_ENABLED")
	useCors := corsEnabled == "1" || corsEnabled == "true"

	server := &http.Server{
		Addr: ":" + httpPort,
		Handler: func() http.Handler {
			if useCors {
				return corsMiddleware(router)
			}
			return router
		}(),
	}

	log.Println("HTTP server listening on port", httpPort)
	if err := server.ListenAndServe(); err != nil {
		log.Println("Error starting HTTP server:", err)
	}
}