| 267 | migrate.RunMigrate(e.db, e.logger) |
| 268 | } |
| 269 | func (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 | |
| 293 | func (e *KubePiServer) setUpTtyEntrypoint() { |
| 294 | f, err := os.OpenFile("init-kube.sh", os.O_CREATE|os.O_RDWR, 0755) |