Serve static assets

Provide a static assets route for use with helm or other air-gap needs.
This commit is contained in:
Erik Wilson 2019-03-18 11:50:20 -07:00 committed by Erik Wilson
parent 697c6e1580
commit 608f3a4e80
2 changed files with 9 additions and 1 deletions

View File

@ -24,7 +24,7 @@ import (
const (
namespace = "kube-system"
image = "rancher/klipper-helm:v0.1.3"
image = "rancher/klipper-helm:v0.1.4"
label = "helm.k3s.cattle.io/chart"
)

View File

@ -2,6 +2,7 @@ package server
import (
"net/http"
"path/filepath"
"strconv"
"github.com/gorilla/mux"
@ -15,6 +16,7 @@ const (
binaryMediaType = "application/octet-stream"
pbMediaType = "application/com.github.proto-openapi.spec.v2@v1.0+protobuf"
openapiPrefix = "openapi."
staticURL = "/static/"
)
type CACertsGetter func() (string, error)
@ -28,8 +30,10 @@ func router(serverConfig *config.Control, tunnel http.Handler, cacertsGetter CAC
authed.Path("/v1-k3s/node.key").Handler(nodeKey(serverConfig))
authed.Path("/v1-k3s/config").Handler(configHandler(serverConfig))
staticDir := filepath.Join(serverConfig.DataDir, "static")
router := mux.NewRouter()
router.NotFoundHandler = authed
router.PathPrefix(staticURL).Handler(serveStatic(staticURL, staticDir))
router.Path("/cacerts").Handler(cacerts(cacertsGetter))
router.Path("/openapi/v2").Handler(serveOpenapi())
router.Path("/ping").Handler(ping())
@ -110,3 +114,7 @@ func ping() http.Handler {
resp.Write(data)
})
}
func serveStatic(urlPrefix, staticDir string) http.Handler {
return http.StripPrefix(urlPrefix, http.FileServer(http.Dir(staticDir)))
}