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: Mask IP Address
// TODO: Query DB to determine whether visitor is returning // 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() q := r.URL.Query()
visit := models.Visit{ visit := models.Visit{
Path: q.Get("p"), Path: q.Get("p"),
IpAddress: r.RemoteAddr, IpAddress: ipAddress,
ReferrerUrl: q.Get("r"), ReferrerUrl: q.Get("r"),
BrowserLanguage: q.Get("l"), BrowserLanguage: q.Get("l"),
ScreenResolution: q.Get("sr"), ScreenResolution: q.Get("sr"),

View File

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