Added api host guard

This commit is contained in:
2026-04-03 10:31:19 +02:00
parent 1aba69cfb5
commit a2e5c735a6
3 changed files with 32 additions and 6 deletions
+9 -1
View File
@@ -6,6 +6,8 @@ import (
"path/filepath"
"quay/app/cachedrepo"
"quay/app/handlers"
"quay/app/middleware"
"quay/app/models"
"quay/internal/config"
"quay/internal/database"
"quay/internal/envconfig"
@@ -19,7 +21,7 @@ func Register(app *fiber.App, cfg *config.Config, envCfg *envconfig.EnvConfig, d
updateSiteHandler := handlers.NewUpdateSiteHandler(cfg, envCfg)
siteHandler := handlers.NewSiteHandler(siteRepository)
api := app.Group("/api/v1")
api := app.Group("/api/v1", middleware.APIHostGuard(envCfg.ApiHost))
api.Get("/health", handlers.HealthCheck)
api.Post("/update", updateSiteHandler.PostUpdate)
@@ -48,6 +50,12 @@ func Register(app *fiber.App, cfg *config.Config, envCfg *envconfig.EnvConfig, d
api.Put("/headers/:id", siteHandler.PutHeader)
api.Delete("/headers/:id", siteHandler.DeleteHeader)
api.Use(func(c fiber.Ctx) error {
return c.Status(fiber.StatusNotFound).JSON(&models.APIError{
Message: "Endpoint not found",
})
})
storagePath, err := filepath.Abs(envCfg.StoragePath)
if err != nil {
log.Fatalf("Failed to resolve storage path: %v", err)