Redirect clash hello to external ui

This commit is contained in:
世界 2022-09-13 17:29:57 +08:00
parent 07b6db23c1
commit e8f4c2d36f
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -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{