Added regex option to forward rules

This commit is contained in:
2026-03-31 12:45:56 +02:00
parent 55348057a0
commit dcc8201099
3 changed files with 49 additions and 13 deletions
+9 -1
View File
@@ -1,6 +1,7 @@
package handlers
import (
"log"
"os"
"path/filepath"
"quay/internal/config"
@@ -18,7 +19,14 @@ func NewStaticHandler(storagePath string, siteMap map[string]config.SiteConfig)
urlPath := filepath.Clean(c.Path())
for _, rule := range site.ForwardRules {
if rule.Source == urlPath {
if rule.Regex && rule.Compiled != nil {
match := rule.Compiled.FindStringSubmatchIndex(urlPath)
if match != nil {
dest := rule.Compiled.ExpandString([]byte{}, rule.Destination, urlPath, match)
log.Printf("Forwarding %s to %s based on regex rule", urlPath, dest)
return c.Redirect().Status(rule.StatusCode).To(string(dest))
}
} else if rule.Source == urlPath {
return c.Redirect().Status(rule.StatusCode).To(rule.Destination)
}
}