Skip to content

Commit

Permalink
Support reverse-proxies by using X-Real-Ip
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelcmtd committed Jul 18, 2023
1 parent ef15800 commit 3132eb4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import (
)

func main() {
// TODO: prometheus
cm3.ListenAndServeHttp(":8080", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, regexp.MustCompile(`:\d+$`).ReplaceAllString(r.RemoteAddr, ""))
})
if realIp, hasRealIp := r.Header["X-Real-Ip"]; hasRealIp && len(realIp) == 1 {
fmt.Fprintln(w, realIp[0])
} else {
fmt.Fprintln(w, regexp.MustCompile(`:\d+$`).ReplaceAllString(r.RemoteAddr, ""))
}
})
}

0 comments on commit 3132eb4

Please sign in to comment.