Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mherwig committed Feb 6, 2025
1 parent adb7fc8 commit bca4c07
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 6 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions internal/api/any.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
18 changes: 18 additions & 0 deletions internal/utils/browser.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion manifest/helm/cosmoparrot/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ service:
ingress:
enabled: false
host: cosmoparrot.example.com
annotations: []
annotations:
tls:
enabled: false
secretName: cosmoparrot-tls
Expand Down

0 comments on commit bca4c07

Please sign in to comment.