add suport for x-forwarded-for header

This commit is contained in:
Danny van Kooten 2016-11-25 16:39:51 +01:00
parent 78932ede14
commit 3c77eb14b1
2 changed files with 9 additions and 3 deletions

View File

@ -34,11 +34,16 @@ func CollectHandler(w http.ResponseWriter, r *http.Request) {
// TODO: Mask IP Address
// TODO: Query DB to determine whether visitor is returning
ipAddress := r.RemoteAddr
headerForwardedFor := r.Header.Get("X-Forwarded-For")
if( headerForwardedFor != "" ) {
ipAddress = headerForwardedFor
}
q := r.URL.Query()
visit := models.Visit{
Path: q.Get("p"),
IpAddress: r.RemoteAddr,
IpAddress: ipAddress,
ReferrerUrl: q.Get("r"),
BrowserLanguage: q.Get("l"),
ScreenResolution: q.Get("sr"),

View File

@ -12,17 +12,18 @@ class Realtime extends Component {
}
this.fetchData = this.fetchData.bind(this);
this.fetchData();
window.setInterval(this.fetchData, 6000);
}
fetchData() {
return fetch('/api/visits/count/realtime', {
credentials: 'include'
}).then((r) => {
if( r.ok ) { r.json(); }
if( r.ok ) { return r.json(); }
throw new Error();
}).then((data) => {
this.setState({ count: data })
}).catch((e) => {});
});
}
render() {