fix X-Forwarded-For

This commit is contained in:
Daniel Mason 2021-03-28 22:07:11 +13:00
parent 16531f9fa1
commit d2e309b699
5 changed files with 8 additions and 5 deletions

View File

@ -8,8 +8,8 @@ import (
"strings" "strings"
"time" "time"
"git.m2.nz/go-scrobble/internal/goscrobble"
"github.com/joho/godotenv" "github.com/joho/godotenv"
"gitlab.com/idanoo/go-scrobble/internal/goscrobble"
) )
func main() { func main() {

View File

@ -16,6 +16,8 @@ These are stored in `web/.env.production` and `web/.env.development`
REDIS_PREFIX="gs:" // Redis key prefix REDIS_PREFIX="gs:" // Redis key prefix
REDIS_AUTH="" // Redis password REDIS_AUTH="" // Redis password
TIMEZONE= // Used for MySQL connection
JWT_SECRET= // 32+ Char JWT secret JWT_SECRET= // 32+ Char JWT secret
JWT_EXPIRY=86400 // JWT expiry JWT_EXPIRY=86400 // JWT expiry

2
go.mod
View File

@ -1,4 +1,4 @@
module git.m2.nz/go-scrobble module gitlab.com/idanoo/go-scrobble
go 1.16 go 1.16

View File

@ -45,10 +45,11 @@ func getUserIp(r *http.Request) net.IP {
var ip net.IP var ip net.IP
host, _, _ := net.SplitHostPort(r.RemoteAddr) host, _, _ := net.SplitHostPort(r.RemoteAddr)
if contains(ReverseProxies, host) { if contains(ReverseProxies, host) {
forwardedFor := r.Header.Get("X-FOWARDED-FOR") forwardedFor := r.Header.Get("X-Forwarded-For")
if forwardedFor != "" { if forwardedFor != "" {
host = forwardedFor host = forwardedFor
} }
// realIp := r.Header.Get("X-Real-IP")
} }
ip = net.ParseIP(host) ip = net.ParseIP(host)

View File

@ -10,11 +10,11 @@ function Home() {
</p> </p>
<a <a
className="App-link" className="App-link"
href="https://git.m2.nz/idanoo/go-scrobble" href="https://gitlab.com/idanoo/go-scrobble"
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
> >
git.m2.nz/idanoo/go-scrobble gitlab.com/idanoo/go-scrobble
</a> </a>
</div> </div>
); );