MCPcopy Create free account
hub / github.com/1Panel-dev/KubePi / setWebkubectlProxy

Method setWebkubectlProxy

internal/server/server.go:269–291  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

267 migrate.RunMigrate(e.db, e.logger)
268}
269func (e *KubePiServer) setWebkubectlProxy() {
270 handler := func(ctx *context.Context) {
271 p := ctx.Params().Get("p")
272 if strings.Contains(p, "root") {
273 ctx.Request().URL.Path = strings.ReplaceAll(ctx.Request().URL.Path, "root", "")
274 ctx.Request().RequestURI = strings.ReplaceAll(ctx.Request().RequestURI, "root", "")
275 }
276 u, _ := url.Parse("http://localhost:8080")
277 proxy := httputil.NewSingleHostReverseProxy(u)
278 proxy.ModifyResponse = func(resp *http.Response) error {
279 if resp.StatusCode == iris.StatusMovedPermanently {
280 // 重定向重写
281 if resp.Header.Get("Location") == "/kubepi/webkubectl/" {
282 resp.Header.Set("Location", "/kubepi/webkubectl/root")
283 }
284 }
285 return nil
286 }
287 proxy.ServeHTTP(ctx.ResponseWriter(), ctx.Request())
288 }
289 e.rootRoute.Any("/webkubectl/{p:path}", handler)
290 e.rootRoute.Any("webkubectl", handler)
291}
292
293func (e *KubePiServer) setUpTtyEntrypoint() {
294 f, err := os.OpenFile("init-kube.sh", os.O_CREATE|os.O_RDWR, 0755)

Callers 1

bootstrapMethod · 0.95

Calls 2

GetMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected