Skip to content

Commit

Permalink
Add codespaces config
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaharagon authored Apr 5, 2024
1 parent de38023 commit 70df6d9
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
26 changes: 26 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/go
{
"name": "Go",
"image": "mcr.microsoft.com/devcontainers/go:1-1.22-bookworm",
"features": {
"ghcr.io/devcontainers/features/go:1": {
"version": "latest"
},
"ghcr.io/azutake/devcontainer-features/go-packages-install:0": {
"PACKAGES": "github.com/caddyserver/xcaddy/cmd/xcaddy@latest"
},
"ghcr.io/devcontainers-contrib/features/caddy:1": {
"version": "latest",
"golangVersion": "latest"
}
},
"customizations": {
"vscode": {
"extensions": [
"GitHub.copilot",
"matthewpi.caddyfile-support"
]
}
}
}
9 changes: 7 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: "gomod" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "monthly"
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
19 changes: 19 additions & 0 deletions test/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
# see: https://caddyserver.com/docs/caddyfile/directives#directive-order
order umami before method
admin off
}

:22111 {
umami {
event_endpoint "https://example.net/api/send"
website_uuid "0cdf6f5b-9b3b-4815-9d22-8cb4d6132781"
allowed_extensions "" .html .htm
client_ip_header CF-Connecting-IP
trusted_ip_header X-Forwarded-For
cookie_consent path_only
cookie_resolution
device_detection
}
respond "Hello, world!"
}
13 changes: 6 additions & 7 deletions umami.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ func (p Umami) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.
return err
}

p.logger.Debug("Allowed", zap.Int("allowed", p.GetAllowed(r)))

// Check if analytics should be performed.
p.logger.Debug("Check if analytics should be performed:", zap.Int("allowed", p.GetAllowed(r)))
if p.GetAllowed(r) == 0 {
return nil
}
Expand Down Expand Up @@ -156,16 +154,16 @@ func (p Umami) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.
req.Header.Set(p.ClientIPHeader, visitorIP)
}

p.logger.Debug("IP", zap.String("IP", req.Header.Get("X-Forwarded-For")))
p.logger.Debug("User-Agent", zap.String("User-Agent", req.UserAgent()))
p.logger.Debug("Body", zap.Any("Body", body))
p.logger.Debug("IP:", zap.String("IP", req.Header.Get("X-Forwarded-For")))
p.logger.Debug("User-Agent:", zap.String("User-Agent", req.UserAgent()))
p.logger.Debug("Body:", zap.Any("visitorInfo", visitorInfo))

resp, err := client.Do(req)
if err != nil {
p.logger.Warn("Error sending visitor info", zap.Error(err))
return
} else {
p.logger.Info("Visitor info sent", zap.Int("status", resp.StatusCode))
p.logger.Debug("Visitor info sent", zap.Int("status", resp.StatusCode))
}
defer resp.Body.Close()

Expand Down Expand Up @@ -225,6 +223,7 @@ func (p *Umami) GetClientIP(r *http.Request) string {
if p.GetAllowed(r) != 1 {
visitorIP = "240.16.0.1"
}
p.logger.Debug("Returning visitor IP to umami:", zap.String("IP", visitorIP))
return visitorIP
}

Expand Down

0 comments on commit 70df6d9

Please sign in to comment.