A look back at the webserver


If you have read this blog you'll know I'm moving from hugo to a custom webserver. I'm happy to say the new blog is ready to be switched over too, it currently is on https://new.nullrequest.com and this weekend will be moved to https://nullrequest.com. I'm currently writing this post in the new editor. Its really a big upgrade over hugo for me. I learned a lot writing the backend code for the blog as well as the frontend. HTML/CSS has never been my fortay so I always fell back to bootstrap and never really got into writing a lot of my code(I still use <center> to center divs). So actually making a blog I'm proud of using something like tailwind and custom css has been a big confidence boost for me. I'd like to talk about how i started with my writing the server and how it has changed over time.

How it began

I can't talk about the architecture of this without going back to the start. When I started I tried to make a fs->html server that would read markdown files and return them render neatly in HTML. While this started out fast it quickly ran into rough edges. For example data about what posts where present, what tags they had and when then were published were stored in the font matter. My solution was to preload everything into a json file like bellow.

  "posts": [
			"title": "Archlinux with secureboot on a nvidia machine",
			"date": "2022-03-26T19",
			"tags": ["arch", "linux","secureboot", "nvidia"],
			"draft": "false"

This resulted in a very fast but also very restricted server, every time I wanted to update a post, add or delete a post I would have to run a tool to regenerate the json and finally restart the webserver. While it was fast and different to the bog static site and it was a webserver( a goal i wanted) I never intended to replace the blog with it, more at the time experiment with a new architecture that might lead to better performance which I was facing a massive issue with. At the time I was running nginx on a Core2Duo, nginx is a server then benefits from more threads, for its workers in my case I old had 2 threads and the ethernet port was old meaning it was capped at 1mb/s. Which limited the initial response time(over a second at the worst). So this was supposed to fix that issue. Looking back it would have been a upgrade if I didn't stick it behind nginx which clearly didn't like running on a Core2Duo.

Auth, the first steps

At the time I thought about splitting out the UI to a frontend written in svelte and serving it using nginx while using the /api sub header to send requests to the webserver, after bouncing between svelte, vue and astro as frontend ui's never really getting a grasp on how to use any I ended up using just plain HTML/CSS and JS which turned out to be the best choice since now I could drop nginx from the stack. Before I switched to a html ui I wanted to add a post editor to write (at the time I still wanted to write a file for every post). My first goal was to get auth in place to make sure I was the only one who could write posts. Thus I made some choices early on, postgresql as a db, dropping a registration url and sifting comments to a 3rd party solution.

As time progressed with the project I made the choice to store posts in the postgresql(a very good choice which lead to better speeds and less code complexity). I thought about serving static assets from ngnix but eventually settled on having that inside my server, I may consider setting up a reverse proxy to serve only static files but as of now I have no need to use a reverse proxy as cloudflare already acts as reverse proxy for me, adding another proxy just leads to larger latencies and worse performance for people using the site.

The future

The last step to be ready to switch my blog to my old blog was to finish writing tag support but several failed attempts eventually lead to finally with the help of a few friends a working tag system that allows me to reverse look up posts by tag and to allow me to be one to one with my old blog allowing me to easily switch to my new blog. The only thing holding me back is the fear everything will break and I will have to figure out how to fix it myself. As time goes on I'll be adding functionality like webmentions(when I figure out how they work), Some form of light mode because some people like it???? like I have not met anyone who really uses light mode outside of a joke. Well that's all for now

-- This is nullrequest signing off