feat: add GoongController to proxy requests and manage caching headers
All checks were successful
Build and Release / release (push) Successful in 1m31s
All checks were successful
Build and Release / release (push) Successful in 1m31s
This commit is contained in:
@@ -46,6 +46,8 @@ func (ctrl *goongController) Proxy(c fiber.Ctx) error {
|
|||||||
targetURL = decodedURL
|
targetURL = decodedURL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
targetURL = strings.TrimPrefix(targetURL, "/")
|
||||||
|
|
||||||
if strings.HasPrefix(targetURL, "https:/") && !strings.HasPrefix(targetURL, "https://") {
|
if strings.HasPrefix(targetURL, "https:/") && !strings.HasPrefix(targetURL, "https://") {
|
||||||
targetURL = strings.Replace(targetURL, "https:/", "https://", 1)
|
targetURL = strings.Replace(targetURL, "https:/", "https://", 1)
|
||||||
} else if strings.HasPrefix(targetURL, "http:/") && !strings.HasPrefix(targetURL, "http://") {
|
} else if strings.HasPrefix(targetURL, "http:/") && !strings.HasPrefix(targetURL, "http://") {
|
||||||
@@ -83,17 +85,24 @@ func (ctrl *goongController) Proxy(c fiber.Ctx) error {
|
|||||||
c.Set(k, v)
|
c.Set(k, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.Set("Access-Control-Allow-Origin", "*")
|
||||||
|
c.Response().Header.Del("Access-Control-Allow-Credentials")
|
||||||
c.Set("Vary", "Origin")
|
c.Set("Vary", "Origin")
|
||||||
c.Set("Cross-Origin-Resource-Policy", "cross-origin")
|
c.Set("Cross-Origin-Resource-Policy", "cross-origin")
|
||||||
|
|
||||||
if c.Method() == "GET" && statusCode == fiber.StatusOK {
|
if c.Method() == "GET" && statusCode == fiber.StatusOK {
|
||||||
isStaticAsset := strings.Contains(targetURL, "/tiles/") ||
|
cleanURL := targetURL
|
||||||
strings.Contains(targetURL, "/fonts/") ||
|
if idx := strings.Index(cleanURL, "?"); idx != -1 {
|
||||||
strings.Contains(targetURL, "/glyphs/") ||
|
cleanURL = cleanURL[:idx]
|
||||||
strings.HasSuffix(targetURL, ".pbf") ||
|
}
|
||||||
strings.HasSuffix(targetURL, ".png") ||
|
|
||||||
strings.HasSuffix(targetURL, ".jpg") ||
|
isStaticAsset := strings.Contains(cleanURL, "/tiles/") ||
|
||||||
strings.HasSuffix(targetURL, ".webp")
|
strings.Contains(cleanURL, "/fonts/") ||
|
||||||
|
strings.Contains(cleanURL, "/glyphs/") ||
|
||||||
|
strings.HasSuffix(cleanURL, ".pbf") ||
|
||||||
|
strings.HasSuffix(cleanURL, ".png") ||
|
||||||
|
strings.HasSuffix(cleanURL, ".jpg") ||
|
||||||
|
strings.HasSuffix(cleanURL, ".webp")
|
||||||
|
|
||||||
if !isStaticAsset {
|
if !isStaticAsset {
|
||||||
c.Set("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0")
|
c.Set("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0")
|
||||||
|
|||||||
Reference in New Issue
Block a user