~porkbrain/template-axum

Template for axum based web server
* Using `Views::BASE` and `Views::BASE_XL` str constants.
Using 4 spaces for indentation in sql files
Removing duplicate handlebar helpers. Handlebars by default supports helpers for bool ops. See <https://github.com/sunng87/handlebars-rust/blob/a970c28daaec820ae4ce6558195ce58f78b95081/src/helpers/helper_extras.rs#L11>

refs

main
browse  log 

clone

read-only
https://git.sr.ht/~porkbrain/template-axum
read/write
git@git.sr.ht:~porkbrain/template-axum

You can also use your local clone with git send-email.

#Template: Axum Web Server

This templates prepares a starting point for a web server with axum. I use it for my personal projects and therefore it contains some opinionated choices. It comes with a simple UI and assumes no authentication.

Some things to be aware of:

  • search for "foobar" (case insensitively) to find placeholders
  • reads declared environment variables into a config struct
  • uses two error types
    • anyhow for general errors
    • custom AppError for web server errors that should be converted into an http status
  • uses handlebars for templating
    • has two templates: base with a capped width container and base_xl for full page container
    • contains some custom helpers
  • has some default routes:
    • serves homepage under GET /
    • serves static files from assets directory under /assets route
      • has a default favicon with my avatar
    • serves a settings page under GET /settings
      • these are global settings for the web server that are handy to adjust from UI
    • edits settings under POST /settings
      • uses application/x-www-form-urlencoded body content type
      • stores settings in database
  • comes with a bundled Sqlite database
    • uses rusqlite connection behind a mutex in web server's state
    • the default env configuration uses in-memory database
    • auto-loads migrations from migrations directory

#Get started

Copy the .env.example file to .env.

Now you have two options: (a) run the server on host machine with $ cargo run or (b) run it in a docker container.

For (b), install cross to compile the project for the same target that this Dockerfile uses. Then run $ just up or, if you don't have just, look for the recipe with $ cat justfile.

Finally, visit http://localhost:8000 in your browser.

Feel free to delete Dockerfile.dev, docker-compose.dev.yml, Cross.toml or justfile.

Do not follow this link