About this Server

This server is fully written in Rust. Several of its non-dynamic pages, at the time of this writing all pages excepts the downloadable contents, are served from memory instead of disk, prerendered into html templates. The server can be reloaded without the necessity for a restart with a secret 256 bit key.


So this is Rust? But web is HTML, CSS, JS, Node, Vue and companions?

Traditionally, this might be true. There are several issues with this setup, huge dependency folders just being one of them. In comparison, this server only needs a single statically linked binary with the size of 11MB. Then there is a certain performance edge, both for memory usage and processing speed. It's currently not planned to serve any highly-dynamic content from this site, such as chats or massive social networks. As such, preprocessing can be done to an extent not easily possible in preconfigured, more widespread setups. For example, this post you are currently viewing is written as a markdown file but prerendered as the complete html page once at startup, or when the server is reloaded.

Rust was chosen above other compiled languages, such as C++, Java, or Haskell, because I like its mix of strong safety guarantees, the normalizing, linear type system and its already extensive open source package ecosystem.

Directory structure

To give a basic idea of the directory structure, here's how files are organized:

.            # Top level, configuration and file for path `/`
|- articles  # Articles, either html or markdown
|- static    # Small unchanging files, indexed and preloaded to memory
|- styled    # Other pages rendered with the global templates
|- files     # Larger indexed files, served from disk to save memory usage
\- templates # Templates for the templating engine, `Tera`


This server is based on rocket, with a few libraries for markdown, templates, serialization and time. Without further ado, here's the complete list, preformatted for use in Cargo.toml:

rocket = "^0.3.4"
rocket_codegen = "*"
notify = "^4.0"
pulldown-cmark = "^0.1.0"
tera = "^0.10"
serde = "*"
serde_derive = "*"
serde_yaml = "*"
simple-signal = "^1.1"
datetime = "^0.4.7"

The intention behind simple-signal was once to include a reload button as a unix signal handler but instead a special path handler proved to be sufficient. Reloading into a new binary, with execv or similar, is not currently supported but might be added should the need arise. This can not safeguard against crashing at startup, however, and would thus be unsafer than the current system.

Published on
Last updated