URL redirect service in Rust

I’ve accidentally implemented an informally-specified, incomplete, buggy version of mod_rewrite. My excuse is that I didn’t think of that before I’d done the work.

Which means I have a tiny piece of Rust code, deployed via a Docker container over at Northflank, to redirect from one domain and blogging URL scheme to a different domain (to keep links working). 

At compile time it loads a TOML configuration file of mappings:

target = "https://r.dallaway.com"

[[page]]
path = "/posts_feed"
aliases = [
"/rss.xml",
]

[[page]]
path = "/posts/rusts-future-combinators"
aliases = [
"/posts/2022-05-14-rust-futures-table/",
"/2022/05/14/rust-futures-table",
"/2022/05/14/rust-futures-table.html",
]

It matches the incoming request, which is an alias, and issues a redirect to the path on the target host.

There are three files in the source:

  • a representation and parser for the map of pages;
  • the server element using Axum to do the HTTP work; and 
  • a main to start it.