Given the current situation with COVID-19, it so happened that I have a whole lot more free time to spend on side projects. One day I was reading a reddit cpp thread about web development in C++ where I stumbled upon library called Wt. As I have lots of experience developing desktop GUI applications, Wt caught my attention - so I started learning more about it.
About 4 weeks later, I’m writing my first post…
Wt - backbone of cxxblog
Usually C++ and web development doesn’t mix, at least I thought so. Wt quickly changed my mind on that. It’s a widget-based framework designed for single-page web applications. Basically, you write a GUI that is translated to HTML and runs on embedded web server (there’s also a possibility to run it in FastCGI mode, though it seems most focus is put on wthttp connector). In order to cover vast range of devices, Wt utilizes different approaches for serving content:
- WebSocket connection (must be explicitly enabled).
- Ajax session with HTML5 History for navigation.
- HTML fallback session for older devices / crawlers.
Framework covers most commonly used user controls - buttons, line edits, text areas, menus. In addition it provides a special widget - Wt::WTemplate that can take HTML template as string with placeholders, bind values (or other widgets) to them and render it. This approach helps a lot with styling and cxxblog uses this feature all over the place.
cxxblog - yet another blog app
While I was developing cxxblog, many people asked me why not use already existing solutions, for example Wordpress. Well, I wanted something “mine”, something that will be fairly easy, will support PostgreSQL (why Wordpress does not support it is beyond my comprehension). But the most compelling reasons are: chance to learn something new (Wt) and learn what’s new in C++17 (last C++ project I was working on was restricted to C++14).
Okay, so what can it do?
- Basic post management. Post writing, publishing, hiding, editing (with drafts).
- Attachments stored in database for the sake of easy backup management (my databases are dumped every day and backed up, so recovering cxxblog would be as simple as restoring last database dump).
- Markdown formatting (thanks to cmark-gfm) with code highlighting (duh, blog for developer).
- About page for the blog and editors (including contact details, avatars, visible name).
- Responsive design based on Bootstrap 3 (unfortunately Wt doesn’t support Bootstrap 4 yet).
How can I use it?
Deployment is fairly easy, once you get through the compilation process. Besides Wt, cxxblog doesn’t depend on anything else than Boost (but that’s a given since it’s a dependency of Wt). Project is managed by CMake, so building it boils down to few commands (assuming you have CMake 3.14+ and Wt installed):
git clone https://github.com/adrian-007/cxxblog.git cxxblog cd cxxblog; mkdir build; cd build; cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/path/where/cxxblog/will/be/installed ../ make install
/opt/cxxblog, you can run it with following command:
/opt/cxxblog/cxxblog --approot=approot --docroot=docroot;/resources,/assets --http-listen 0.0.0.0:80
And that’s it!
Are we there yet?
There are still some places for improvement, for sure there are some bugs creeping around, but overall, I’m satisfied with it to the point that I feel confident enough to use it for my personal page and put it out to the public.