You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/dockerui.go

42 lines
843 B

package main
import (
"flag"
"log"
"net/http"
"net/http/httputil"
"net/url"
)
var (
endpoint = flag.String("e", "", "Dockerd endpoint")
addr = flag.String("p", ":9000", "Address and port to serve dockerui")
assets = flag.String("a", ".", "Path to the assets")
)
func createHandler(dir string, dockerEndpoint string) http.Handler {
mux := http.NewServeMux()
fileHandler := http.FileServer(http.Dir(dir))
u, err := url.Parse(dockerEndpoint)
if err != nil {
log.Fatal(err)
return nil
}
reverseProxy := httputil.NewSingleHostReverseProxy(u)
mux.Handle("/dockerapi/", http.StripPrefix("/dockerapi", reverseProxy))
mux.Handle("/", fileHandler)
return mux
}
func main() {
flag.Parse()
handler := createHandler(*assets, *endpoint)
if err := http.ListenAndServe(*addr, handler); err != nil {
log.Fatal(err)
}
}