🏡 go home...
📚 go back...
created 2022/09/17 category software
an ethical website view counter i wrote to deploy on this website
📊 see it in action
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*
*today in time of the server
i used to just have lighttpd providing http(s), now i have it doing strictly http to port 8000 and have viewcounter running on port 8001
now i am able to use caddy to not only act as a reverse proxy to combine both services into one website, but also to provide ssl to both lighttpd and viewcounter