mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 09:13:49 +08:00
feat: 优化app路由加载
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
||||
"github.com/go-chi/chi/v5"
|
||||
|
||||
"github.com/TheTNB/panel/internal/app"
|
||||
"github.com/TheTNB/panel/internal/apps"
|
||||
"github.com/TheTNB/panel/internal/http/middleware"
|
||||
"github.com/TheTNB/panel/internal/route"
|
||||
)
|
||||
@@ -25,7 +24,6 @@ func initHttp() {
|
||||
// add route
|
||||
route.Http(app.Http)
|
||||
route.Ws(app.Http)
|
||||
apps.Boot(app.Http)
|
||||
|
||||
srv := hlfhr.New(&http.Server{
|
||||
Addr: fmt.Sprintf(":%d", app.Conf.MustInt("http.port")),
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
|
||||
"github.com/TheTNB/panel/internal/apps"
|
||||
"github.com/TheTNB/panel/internal/embed"
|
||||
"github.com/TheTNB/panel/internal/http/middleware"
|
||||
"github.com/TheTNB/panel/internal/service"
|
||||
@@ -259,6 +260,11 @@ func Http(r chi.Router) {
|
||||
r.Post("/start", systemctl.Start)
|
||||
r.Post("/stop", systemctl.Stop)
|
||||
})
|
||||
|
||||
r.Route("/apps", func(r chi.Router) {
|
||||
r.Use(middleware.MustLogin)
|
||||
apps.Boot(r)
|
||||
})
|
||||
})
|
||||
|
||||
r.NotFound(func(writer http.ResponseWriter, request *http.Request) {
|
||||
|
||||
@@ -47,7 +47,7 @@ func All() []*types.App {
|
||||
func Boot(r chi.Router) {
|
||||
apps.Range(func(_, app any) bool {
|
||||
if p, ok := app.(*types.App); ok {
|
||||
r.Route(fmt.Sprintf("/api/apps/%s", p.Slug), p.Route)
|
||||
r.Route(fmt.Sprintf("/%s", p.Slug), p.Route)
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user