mirror of https://github.com/k3s-io/k3s
parent
bba01c7a54
commit
6e98ce34ca
|
@ -36,9 +36,9 @@ func (f *Factory) NewCmdProxy(out io.Writer) *cobra.Command {
|
|||
clientConfig, err := f.ClientConfig(cmd)
|
||||
checkErr(err)
|
||||
|
||||
server, err := kubectl.NewProxyServer(GetFlagString(cmd, "www"), clientConfig, port)
|
||||
server, err := kubectl.NewProxyServer(GetFlagString(cmd, "www"), clientConfig)
|
||||
checkErr(err)
|
||||
glog.Fatal(server.Serve())
|
||||
glog.Fatal(server.Serve(port))
|
||||
},
|
||||
}
|
||||
cmd.Flags().StringP("www", "w", "", "Also serve static files from the given directory under the prefix /static")
|
||||
|
|
|
@ -29,12 +29,11 @@ import (
|
|||
// ProxyServer is a http.Handler which proxies Kubernetes APIs to remote API server.
|
||||
type ProxyServer struct {
|
||||
httputil.ReverseProxy
|
||||
Port int
|
||||
}
|
||||
|
||||
// NewProxyServer creates and installs a new ProxyServer.
|
||||
// It automatically registers the created ProxyServer to http.DefaultServeMux.
|
||||
func NewProxyServer(filebase string, cfg *client.Config, port int) (*ProxyServer, error) {
|
||||
func NewProxyServer(filebase string, cfg *client.Config) (*ProxyServer, error) {
|
||||
prefix := cfg.Prefix
|
||||
if prefix == "" {
|
||||
prefix = "/api"
|
||||
|
@ -52,9 +51,9 @@ func NewProxyServer(filebase string, cfg *client.Config, port int) (*ProxyServer
|
|||
return proxy, nil
|
||||
}
|
||||
|
||||
// Serve starts the server (http.DefaultServeMux) on TCP port 8001, loops forever.
|
||||
func (s *ProxyServer) Serve() error {
|
||||
addr := fmt.Sprintf(":%d", s.Port)
|
||||
// Serve starts the server (http.DefaultServeMux) on given port, loops forever.
|
||||
func (s *ProxyServer) Serve(port int) error {
|
||||
addr := fmt.Sprintf(":%d", port)
|
||||
return http.ListenAndServe(addr, nil)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue