Vaxry's blog

a programming blog!

I've finally fixed the view count

13 VIII 2022

2.7k

Well, this won't be a long blogpost.

I am letting you all know that the viewcount up to today has been SEVERELY deflated. Why? Because of my stupidity in code, and partially because I just didn't notice. Yes, it seemed a bit off but I just brushed it off as a "who wants to read a programming blog lol". Well, now I know that this was NOT the case.

Basically, since I don't like those huge libraries / frameworks like React or Angular or whatever, my website is written 100% by me, both the backend and frontend, with express, in pure js. That means, of course, that the viewcount was implemented from the ground-up by me.

In order to keep the view count safe from someone spamming F5 and inflating it, I've decided to just log the IPs into a HashMap and in there keep the articles that the particular IP has visited, just expiring after some time. In before you start fuming, the IPs were held in RAM and were never logged. This way seemed like a reasonable way to do that, and it is.

The problem? Since my website is behind cloudflare, all requests come from cloudflare, so one and the same IP... This means, that whenever someone would view the article, my webserver would think they've already seen it, because Cloudflare's IP was logged, and thus not add the view. Ugh.

I've fixed this problem now, as CloudFlare kindly provides the original IP in the headers. And yes, it's not logged either by me, and never will be.

My stupidity shines as usual... I hope it's fixed now. It seems fixed. Please be fixed.


Questions, comments, mistakes? Ping me a mail at vaxry [at] vaxry.net and I'll get back to ya.