Add frontend #1
@@ -0,0 +1,12 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
import "github.com/gofiber/fiber/v3"
|
||||||
|
|
||||||
|
func APIHostGuard(allowedHost string) fiber.Handler {
|
||||||
|
return func(c fiber.Ctx) error {
|
||||||
|
if c.Hostname() != allowedHost {
|
||||||
|
return c.Status(fiber.StatusNotFound).SendString("Not Found")
|
||||||
|
}
|
||||||
|
return c.Next()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"quay/app/cachedrepo"
|
"quay/app/cachedrepo"
|
||||||
"quay/app/handlers"
|
"quay/app/handlers"
|
||||||
|
"quay/app/middleware"
|
||||||
|
"quay/app/models"
|
||||||
"quay/internal/config"
|
"quay/internal/config"
|
||||||
"quay/internal/database"
|
"quay/internal/database"
|
||||||
"quay/internal/envconfig"
|
"quay/internal/envconfig"
|
||||||
@@ -19,7 +21,7 @@ func Register(app *fiber.App, cfg *config.Config, envCfg *envconfig.EnvConfig, d
|
|||||||
updateSiteHandler := handlers.NewUpdateSiteHandler(cfg, envCfg)
|
updateSiteHandler := handlers.NewUpdateSiteHandler(cfg, envCfg)
|
||||||
siteHandler := handlers.NewSiteHandler(siteRepository)
|
siteHandler := handlers.NewSiteHandler(siteRepository)
|
||||||
|
|
||||||
api := app.Group("/api/v1")
|
api := app.Group("/api/v1", middleware.APIHostGuard(envCfg.ApiHost))
|
||||||
api.Get("/health", handlers.HealthCheck)
|
api.Get("/health", handlers.HealthCheck)
|
||||||
|
|
||||||
api.Post("/update", updateSiteHandler.PostUpdate)
|
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.Put("/headers/:id", siteHandler.PutHeader)
|
||||||
api.Delete("/headers/:id", siteHandler.DeleteHeader)
|
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)
|
storagePath, err := filepath.Abs(envCfg.StoragePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to resolve storage path: %v", err)
|
log.Fatalf("Failed to resolve storage path: %v", err)
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type EnvConfig struct {
|
type EnvConfig struct {
|
||||||
Port string
|
Port string
|
||||||
ConfigDir string
|
ConfigDir string
|
||||||
GithubPat string
|
GithubPat string
|
||||||
StoragePath string
|
StoragePath string
|
||||||
DatabasePath string
|
ApiHost string
|
||||||
}
|
}
|
||||||
|
|
||||||
func Load() EnvConfig {
|
func Load() EnvConfig {
|
||||||
@@ -33,10 +33,16 @@ func Load() EnvConfig {
|
|||||||
storagePath = "./storage"
|
storagePath = "./storage"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apiHost := os.Getenv("API_HOST")
|
||||||
|
if apiHost == "" {
|
||||||
|
apiHost = "localhost"
|
||||||
|
}
|
||||||
|
|
||||||
return EnvConfig{
|
return EnvConfig{
|
||||||
Port: port,
|
Port: port,
|
||||||
ConfigDir: configDir,
|
ConfigDir: configDir,
|
||||||
GithubPat: githubPat,
|
GithubPat: githubPat,
|
||||||
StoragePath: storagePath,
|
StoragePath: storagePath,
|
||||||
|
ApiHost: apiHost,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user