This commenting system is built to be as simple as possible. It consists of one endpoint and a couple of lines of inlined JS. It sits on top of Cloudflare Workers, which makes it free for the vast majority of blogs.
You can see it in action on my blog.
A single /comments endpoint is used:
- POST requests create comments
- GET requests retrieve all the comments for an article (using /comments/my-article-url).
If the ZAPIER_URL environment variable URL is set, all comments' data is sent to the webhook to, for example, help with moderation.
Just add a wrangler.toml file and publish the worker. If you're new to this, check out:
- Getting started with Cloudflare Workers.
- The Wrangler documentation.
To display the comments on any page, include a couple of lines of JS:
<script defer>
fetch('https://example.com/comments/this-is-the-path-of-my-article')
.then(response => {
if (response.ok) {
return response.text()
} else {
throw new Error('Something went wrong')
}
}).then(body => {
document.getElementById("comments-list").innerHTML = body
})
</script>