Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubectl proxy: make static prefix configurable #4110

Merged
merged 1 commit into from
Feb 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/kubectl.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ Usage:
--v=0: log level for V logs
--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
-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

```

Expand Down
10 changes: 8 additions & 2 deletions pkg/kubectl/cmd/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cmd

import (
"io"
"strings"

"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
"github.com/golang/glog"
Expand All @@ -36,12 +37,17 @@ func (f *Factory) NewCmdProxy(out io.Writer) *cobra.Command {
clientConfig, err := f.ClientConfig(cmd)
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)
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")
return cmd
}
4 changes: 2 additions & 2 deletions pkg/kubectl/proxy_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type ProxyServer struct {

// NewProxyServer creates and installs a new ProxyServer.
// 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
if prefix == "" {
prefix = "/api"
Expand All @@ -47,7 +47,7 @@ func NewProxyServer(filebase string, cfg *client.Config) (*ProxyServer, error) {
return nil, err
}
http.Handle("/api/", http.StripPrefix("/api/", proxy))
http.Handle("/static/", newFileHandler("/static/", filebase))
http.Handle(staticPrefix, newFileHandler(staticPrefix, filebase))
return proxy, nil
}

Expand Down