Discourse
Discourse is an awesome Open Source forum software that can be used as a mailing list, a discussion forum, and a long-form chat room. I decided to use this software because I knew if I really ran into any issues, I could dig into the code and write custom solutions. I am familiar enough with rails to take a look inside if I need to.
I also liked the layout of the application and I really didn’t want to pay licensing costs for other forum software.
Deploying
To get Discourse setup all you really need is a server with 1 cpu and 1gb of ram and a mail server to send emails from. I used an AWS EC2 instance and Mailgun because both of these offer a free tier. This meant I would be able to run this service at the cost of free.
Discourse has good install guide that basically gets you up and running with discourse pretty quick. I opted for the basic install because there is no reason for me to create a complex setup.
I got the server online and the repo installed and ran the ./discourse-setup
command only to have to run it a few more times due to some technical difficulties.
After some quick debugging everything was back online and ther were no problems.
I decided to use Mailgun because I have used it in the past and they offer a good service. I setup a new mailing list user and added the DNS credentials and I was up and running pretty quickly. Configuring DNS can be tricky if you haven’t done it before.
I went back to my discourse install walk-through and entered the mail credentials and everything was now up and running.
I went to the site forum.itsltns.io
where I set up DNS to point to and the service was ready for me to configure.
DNS
The biggest challenges with this Discourse service is the DNS configurations that need to be made for the mail server, and the discourse applicaiton. Everything else is pretty easy to walk through and configure.
Embedding Forum Comments on Blog Sites
Adding some basic code to the static blog website:
<section class="discourse">
<div id='discourse-comments'></div>
<script type="text/javascript">
DiscourseEmbed = { discourseUrl: 'https://forum.itsltns.io/',
discourseEmbedUrl: 'https://devops.itsltns.io/2019/04/01/Forum-Live.html'
};
(function() {
var d = document.createElement('script'); d.type = 'text/javascript'; d.async = true;
d.src = DiscourseEmbed.discourseUrl + 'javascripts/embed.js';
(document.getElementsByTagName('head')[0] ||
document.getElementsByTagName('body')[0]).appendChild(d);
})();
</script>
</section>
This piece of code allows me to embed a comments section to the site and allows users to comment on posts from the blog site or directly on the post. With everything being automated, my job is made very easy.
For this to work on your site you have to add the embed site, in this case the discourseEmbedUrl:
, to the allowed embed whitelist in the forum.
This can be found in Admin > Customize > Embedding
on the forum site.
For more, I would check out the Embedding Discourse Comments via Javascript.
I got error loading comments
but I fixed this by opening the link to the forum from the blog site.
Clicking the link created a new forum topic based on the blog post.
Conclusions
This post was made a short time after the deployment of the forum. I don’t have as many technical details as I would like, but as I continue to update this as I deploy them.