💾 Archived View for zvava.org › wiki › viewcounter.gmi captured on 2023-07-22 at 16:26:46. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-07-10)
-=-=-=-=-=-=-
created 2022/09/17 category software
an ethical website view counter i wrote to deploy on this website
i wanted to have really basic analytics (if you can even call it that) on my website that A. don't track you and B. can be easily disabled by just disabling javascript
in about 130 lines of vanilla node.js, viewcounter listens to requests on a single path
if it is a GET request, a summary of all the page view counts are returned
if it is a POST request with a page path as a body, that page's view count is incremented
there are two mechanisms in place to prevent abuse of the system
firstly, the url is validated to make sure it's an actual url on the website and not idk a slur or something, of which the result is cached so further requests to the same url can be quickly processed
there is also a 24h ratelimit in place to prevent spam. each ip has a "profile" of when it has last visited a page, if that date is today* then their view is not counted, otherwise the view count is incremented and the date is set to today*
i used to just have lighttpd providing http(s) but now i am able to use caddy[1] to not only act as the web server, but also a reverse proxy to combine both services into one website. it also provides ssl to the entire site automagically