Why I wrote the fx web server

21 points by rikhuijzer


runxiyu

I feel like it’s more of a CMS than a web server

motet-a

(sorry for the technical digression, I know it’s not really the point of the article…)

I just had a quick look at the source code. I looks neat to my eyes. It’s funny because I’m working on a completely unrelated hobby project (a web app as well, but not microblogging) with a very similar tech stack, i.e. Rust, axum, and rusqlite. I spent quite a bit of time fighting against the compiler until I have understood that rusqlite code have to be somewhat isolated from async axum handlers, because rusqlite::Statement is !Send and !Sync… so I use #[axum::debug_handler] everywhere now, it really helps troubleshooting. On the other hand, in your case I guess the mutex in ServerContext also helps to prevent this “!Send/!Sync/futures” syndrom. Currently I have chosen to create a new connection to the database file for every request instead of sharing the same connection between Tokio tasks. I honestly don’t know if it is good or bad, currently I have no issue (I have very little traffic) but for mostly ergonomic reasons I didn’t want to have the DB connection in an axum State… Ideally I guess I should have some sort of pool that assigns one connection per thread, but I don’t think I will change this now (unless someone knows an easy way to do it…)

BTW I have a little database migration system for SQLite I’m really happy with — I mean, not overengineered and quite foolproof in my opinion. I can show you how I did it if you are interested.