🐛 Fix aliasing issue

This commit is contained in:
LittleSheep 2024-08-17 23:52:42 +08:00
parent 5dbe1cf80d
commit 38b52aec2f
3 changed files with 4 additions and 8 deletions

View File

@ -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().

View File

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

View File

@ -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" }