diff --git a/README.md b/README.md index 3dec70b..38f1887 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,24 @@ Alternatively you can run the server in a container: ```bash docker run -p 8080:8080 cosmoparrot ``` + +## Deployment + +For the deployment of Cosmoparrot you can use Kubernetes deployment `manifest/deployment.yaml` and adjust it to your +needs, or you can use and customize the Heln chart located in `manifest/helm`. + +*Helm example:* +``` +helm install cosmoparrot ./manifest/helm/cosmoparrot \ + --namespace custom-namespace --create-namespace \ + --set cosmoparrot.storeKeyRequestHeaders="{X-Request-ID,X-Correlation-ID}" \ + --set image.repository=myregistry.com/cosmoparrot \ + --set image.tag=latest \ + --set ingress.enabled=true \ + --set ingress.host=cosmoparrot.mycompany.com \ + --set imagePullSecrets[0].name=my-pull-secret +``` + ## Contributing We're committed to open source, so we welcome and encourage everyone to join its developer community and contribute, whether it's through code or feedback. diff --git a/internal/api/any.go b/internal/api/any.go index 2d0a907..1cd42ac 100644 --- a/internal/api/any.go +++ b/internal/api/any.go @@ -7,6 +7,7 @@ package api import ( "cosmoparrot/internal/cache" "cosmoparrot/internal/config" + "cosmoparrot/internal/utils" "encoding/json" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/log" @@ -18,6 +19,11 @@ import ( ) func handleAnyRequest(c *fiber.Ctx) error { + userAgent := c.Get("User-Agent") + if c.Path() == "/" && utils.IsBrowser(userAgent) { + return c.Next() + } + var responseBody any if len(c.Body()) > 0 { diff --git a/internal/api/api.go b/internal/api/api.go index 877a10b..d42461b 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -23,17 +23,17 @@ func init() { } func AddHandlers(f embed.FS) { - app.Use("/", filesystem.New(filesystem.Config{ - Root: http.FS(f), - PathPrefix: "web", - })) - api := app.Group("/api") v1 := api.Group("/v1") v1.Get("/requests", handleGetAllRequests) v1.Get("/requests/:key", handleGetRequestByKey) app.Use(handleAnyRequest) + + app.Use("/", filesystem.New(filesystem.Config{ + Root: http.FS(f), + PathPrefix: "web", + })) } func Listen() { diff --git a/internal/utils/browser.go b/internal/utils/browser.go new file mode 100644 index 0000000..bff41cf --- /dev/null +++ b/internal/utils/browser.go @@ -0,0 +1,18 @@ +package utils + +import ( + "strings" +) + +func IsBrowser(userAgent string) bool { + browserKeywords := []string{"mozilla", "chrome", "safari", "firefox", "edge", "opera"} + + str := strings.ToLower(userAgent) + for _, keyword := range browserKeywords { + if strings.Contains(str, keyword) { + return true + } + } + + return false +} diff --git a/manifest/helm/cosmoparrot/values.yaml b/manifest/helm/cosmoparrot/values.yaml index bbf4dd0..d2bb261 100644 --- a/manifest/helm/cosmoparrot/values.yaml +++ b/manifest/helm/cosmoparrot/values.yaml @@ -17,7 +17,7 @@ service: ingress: enabled: false host: cosmoparrot.example.com - annotations: [] + annotations: tls: enabled: false secretName: cosmoparrot-tls