mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Merge pull request #4110 from jimmidyson/proxy-tweaks
kubectl proxy: make static prefix configurable
This commit is contained in:
commit
42fec8ec4e
@ -73,7 +73,8 @@ Usage:
|
|||||||
--v=0: log level for V logs
|
--v=0: log level for V logs
|
||||||
--validate=false: If true, use a schema to validate the input before sending it
|
--validate=false: If true, use a schema to validate the input before sending it
|
||||||
--vmodule=: comma-separated list of pattern=N settings for file-filtered logging
|
--vmodule=: comma-separated list of pattern=N settings for file-filtered logging
|
||||||
-w, --www="": Also serve static files from the given directory under the prefix /static
|
-w, --www="": Also serve static files from the given directory under the specified prefix
|
||||||
|
-P, --www-prefix="/static/": Prefix to serve static files under, if static file dir is specified
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
@ -36,12 +37,17 @@ func (f *Factory) NewCmdProxy(out io.Writer) *cobra.Command {
|
|||||||
clientConfig, err := f.ClientConfig(cmd)
|
clientConfig, err := f.ClientConfig(cmd)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
||||||
server, err := kubectl.NewProxyServer(GetFlagString(cmd, "www"), clientConfig)
|
staticPrefix := GetFlagString(cmd, "www-prefix")
|
||||||
|
if !strings.HasSuffix(staticPrefix, "/") {
|
||||||
|
staticPrefix += "/"
|
||||||
|
}
|
||||||
|
server, err := kubectl.NewProxyServer(GetFlagString(cmd, "www"), staticPrefix, clientConfig)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
glog.Fatal(server.Serve(port))
|
glog.Fatal(server.Serve(port))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cmd.Flags().StringP("www", "w", "", "Also serve static files from the given directory under the prefix /static")
|
cmd.Flags().StringP("www", "w", "", "Also serve static files from the given directory under the specified prefix")
|
||||||
|
cmd.Flags().StringP("www-prefix", "P", "/static/", "Prefix to serve static files under, if static file dir is specified")
|
||||||
cmd.Flags().IntP("port", "p", 8001, "The port on which to run the proxy")
|
cmd.Flags().IntP("port", "p", 8001, "The port on which to run the proxy")
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ type ProxyServer struct {
|
|||||||
|
|
||||||
// NewProxyServer creates and installs a new ProxyServer.
|
// NewProxyServer creates and installs a new ProxyServer.
|
||||||
// It automatically registers the created ProxyServer to http.DefaultServeMux.
|
// It automatically registers the created ProxyServer to http.DefaultServeMux.
|
||||||
func NewProxyServer(filebase string, cfg *client.Config) (*ProxyServer, error) {
|
func NewProxyServer(filebase string, staticPrefix string, cfg *client.Config) (*ProxyServer, error) {
|
||||||
prefix := cfg.Prefix
|
prefix := cfg.Prefix
|
||||||
if prefix == "" {
|
if prefix == "" {
|
||||||
prefix = "/api"
|
prefix = "/api"
|
||||||
@ -47,7 +47,7 @@ func NewProxyServer(filebase string, cfg *client.Config) (*ProxyServer, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
http.Handle("/api/", http.StripPrefix("/api/", proxy))
|
http.Handle("/api/", http.StripPrefix("/api/", proxy))
|
||||||
http.Handle("/static/", newFileHandler("/static/", filebase))
|
http.Handle(staticPrefix, newFileHandler(staticPrefix, filebase))
|
||||||
return proxy, nil
|
return proxy, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user