diff --git a/internal/constant/constant.go b/internal/constant/constant.go index 8f4f5c8b8..844a2b669 100644 --- a/internal/constant/constant.go +++ b/internal/constant/constant.go @@ -103,6 +103,7 @@ const WelcomeHTML = ` {{if .SubConfigs}} @@ -120,7 +121,7 @@ const WelcomeHTML = ` diff --git a/internal/web/handlers.go b/internal/web/handlers.go index eb43dbcc2..3bef11130 100644 --- a/internal/web/handlers.go +++ b/internal/web/handlers.go @@ -1,6 +1,7 @@ package web import ( + "encoding/json" "fmt" "net/http" "text/template" @@ -95,3 +96,15 @@ func (s *Server) HandleReload(w http.ResponseWriter, r *http.Request) { return } } + +func (s *Server) CurrentConfig(w http.ResponseWriter, r *http.Request) { + // return json config + ret, err := json.Marshal(s.cfg) + if err != nil { + writerBadRequestMsg(w, err.Error()) + return + } + w.WriteHeader(http.StatusOK) + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write(ret) +} diff --git a/internal/web/server.go b/internal/web/server.go index c8a51df71..f97f9aba9 100644 --- a/internal/web/server.go +++ b/internal/web/server.go @@ -54,6 +54,7 @@ func NewServer(cfg *config.Config, relayReloader reloader.Reloader) (*Server, er e.GET("/metrics/", echo.WrapHandler(promhttp.Handler())) e.GET("/debug/pprof/*", echo.WrapHandler(http.DefaultServeMux)) e.GET("/clash_proxy_provider/", echo.WrapHandler(http.HandlerFunc(s.HandleClashProxyProvider))) + e.GET("/config/", echo.WrapHandler(http.HandlerFunc(s.CurrentConfig))) e.POST("/reload/", echo.WrapHandler(http.HandlerFunc(s.HandleReload))) return s, nil