From e8f4c2d36ff656b4d1b398d9e81d8db46139fd1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Tue, 13 Sep 2022 17:29:57 +0800 Subject: [PATCH] Redirect clash hello to external ui --- experimental/clashapi/server.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/experimental/clashapi/server.go b/experimental/clashapi/server.go index aa74e9a8..c209a1ae 100644 --- a/experimental/clashapi/server.go +++ b/experimental/clashapi/server.go @@ -80,7 +80,7 @@ func NewServer(router adapter.Router, logFactory log.ObservableFactory, options chiRouter.Use(cors.Handler) chiRouter.Group(func(r chi.Router) { r.Use(authentication(options.Secret)) - r.Get("/", hello) + r.Get("/", hello(options.ExternalUI != "")) r.Get("/logs", getLogs(logFactory)) r.Get("/traffic", traffic(trafficManager)) r.Get("/version", version) @@ -232,8 +232,14 @@ func authentication(serverSecret string) func(next http.Handler) http.Handler { } } -func hello(w http.ResponseWriter, r *http.Request) { - render.JSON(w, r, render.M{"hello": "clash"}) +func hello(redirect bool) func(w http.ResponseWriter, r *http.Request) { + return func(w http.ResponseWriter, r *http.Request) { + if redirect { + http.Redirect(w, r, "/ui/", http.StatusTemporaryRedirect) + } else { + render.JSON(w, r, render.M{"hello": "clash"}) + } + } } var upgrader = websocket.Upgrader{