Adding a commenting system
January 15, 2022
Back story
So, I have my blog site finally going! Great, but it's not much of a blog if I can't get any interaction. Sure, I have Google analytics on my site so at the very least I can see how many people are actually visiting my site (thanks Chinese bots 😅), but that is not even close to the standard of today's web.
Where do you begin? First, let's look at what is available. This Gatsby page lists popular systems already in place. I went through all of them and checked them out first. What I wanted was something that was easy to add to my site. It had to be free, and allow for anonymous comments. I was not very satisfied with what was listed on this page, nor anything else I found in my research. It was on to writing my own custom system!
Writing a custom commenting system
First, I needed to find a database, this too needed to be free. I did some more research and settled on using Heroku with a Postgres addon. This would require an api which I built on this github repo.
The free tier of the database was limited to just 1000 rows. In order to try and limit this I kept the whole system to just one table. Not a good practice, I know. It handled get requests by returning all comments with the path received as a query parameter, and it handled post requests by entering the data into the table. I added a check for the api key, which was just a randomly generated string which can be added to the environment variables. This should prevent posts outside of my site from trying to submit to my database.
The next step was to add the frontend to my site. This was a couple of components for the list per page, the comment itself, and form for adding new comments. I added a local storage item for the name and email so that previously entered information could be saved and automatically added as the fields's inputs. This will help with the lack of a sign in system. But, the more I thought about this the more I disliked it.
There was a flaw with this, anyone could post as anyone. There was no authentication system. Sure, I could add one, but this project is just growing bigger and bigger. I definitely bit off more than I was wanting to chew.
This brought me back to the list of recommended commenting systems. I wanted to take a second look at everything. The top one recommended was Disqus. I figured I could sign up for it, add it to my site and try it out locally. After trying it out, it was everything I wanted. Authentification? Check. Anonymous posts? Check. Moderation? Check.
Conclusion
I think the lesson to learn here is that when you are adding something new to a project you need to first check thoroughly what already exists. And, if you do decide to reinvent the wheel, make sure you truly understand what you need. At the very least, make sure you understand it before you get to the point of no return.