Velvet
(original repo: https://github.com/raffaeleragni/velvet)
A layer of republish and small functions to remove some boilerplate on web stacks.
For a reference/example of a project using it: https://github.com/raffaeleragni/veltes
Stack used
The askama templates, the static RustEmbed will all be compiled in the binary and not require them at runtime in the file system.
The sqlx migrations are not embedded, and will be needed at file system at runtime.
Items of the stack:
- WEB: Axum
- DB: sqlx(postgres,sqlite,mysql)
- Templating: Askama (folder templates/)
- Telemetry: sentry supported
- Metrics: prometheus under /metrics/prometheus
Base route setup
use *;
async
async
Add a database
Adding a .env file with DATABASE_URL=sqlite::memory:.
use *;
async
async
Use an HTTP Client
use *;
async
async
Check JWT token (from bearer or cookies)
Adding a .env file with JWT_SECRET=secret.
use *;
async
async
Support for static files
use *;
async
Add custom metrics
Metrics available at /metrics/prometheus. The custom metrics will be visible as soon as the first use happens, but used within the App, not before.
Note: needs to add crate axum_prometheus.
use *;
async
async
Default routes already implemented
- Status (no-op): http GET /status/liveness
- Metrics: http GET /metrics/prometheus
ENV vars
- SERVER_BIND: [default] default (0.0.0.0) bind network for which to listen on
- SERVER_PORT: [number] (default 8080) port for which to listen on
- DATABASE_URL: postgres://user:pass@host:port/database (if database used) or sqlite::memory:...
- DATABASE_MAX_CONNECTIONS: [number] (default 1)
- STRUCTURED_LOGGING: true|false (default false)
- SENTRY_URL: url inclusive of key for sending telemetry to sentry
To setup TLS use env vars:
- TLS=true (or any string)
- TLS_PEM_CERT=cert.pem
- TLS_PEM_KEY=key.pem