From 38b52aec2fb0e98fc6eb023ff84b5346d76c6efd Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 17 Aug 2024 23:52:42 +0800 Subject: [PATCH] :bug: Fix aliasing issue --- pkg/internal/server/api/directory.go | 9 +++------ pkg/internal/server/api/index.go | 1 - settings.toml | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/pkg/internal/server/api/directory.go b/pkg/internal/server/api/directory.go index 00205be..2eb245a 100644 --- a/pkg/internal/server/api/directory.go +++ b/pkg/internal/server/api/directory.go @@ -25,8 +25,9 @@ func listExistsService(c *fiber.Ctx) error { func forwardServiceRequest(c *fiber.Ctx) error { serviceType := c.Params("service") + ogKeyword := serviceType - aliasingMap := viper.GetStringMapString("services.alias") + aliasingMap := viper.GetStringMapString("services.aliases") if val, ok := aliasingMap[serviceType]; ok { serviceType = val } @@ -39,11 +40,7 @@ func forwardServiceRequest(c *fiber.Ctx) error { ogUrl := c.Request().URI().String() url := c.OriginalURL() - prevUrl := url - url = strings.Replace(url, "/srv/"+serviceType, "/api", 1) - if prevUrl == url { - url = strings.Replace(url, "/cgi/"+serviceType, "/api", 1) - } + url = strings.Replace(url, "/cgi/"+ogKeyword, "/api", 1) url = "http://" + *service.HttpAddr + url log.Debug(). diff --git a/pkg/internal/server/api/index.go b/pkg/internal/server/api/index.go index d293cdd..f725093 100644 --- a/pkg/internal/server/api/index.go +++ b/pkg/internal/server/api/index.go @@ -16,7 +16,6 @@ func MapAPIs(app *fiber.App) { } app.All("/cgi/:service/*", forwardServiceRequest) - app.All("/srv/:service/*", forwardServiceRequest) api := app.Group("/api").Name("API") { diff --git a/settings.toml b/settings.toml index 474475d..faffe90 100644 --- a/settings.toml +++ b/settings.toml @@ -37,5 +37,5 @@ access_token_duration = 300 refresh_token_duration = 2592000 [services] -alias = { id = "auth", uc = "files", co = "interactive", im = "messagings" } +aliases = { id = "auth", uc = "files", co = "interactive", im = "messaging" }