Skip to content

raffaeleragni/velvet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Velvet

(original repo: https://github.com/raffaeleragni/velvet)

A repackage and republish of a combination of crates to create a specific web stack in a consistent and single point of view. This is not meant to be a library with any specific purpose, only a short handing of boilerplate for the common setup and structure of this web stack.

Stack used

The templates and static files will be compiled in the binary and those directories and won't be required at runtime.

Items of the stack:

  • WEB: Axum
  • DB: sqlx(postgres)
  • Templating: Askama (folder templates/)
  • Telemetry: sentry supported

Base route setup

use velvet::prelude::*;

fn index() -> &'static str {
    "Hello world"
}

#[tokio::main]
async fn main() {
    App::new()
        .router(Router::new().route("/", get(index)))
        .start()
        .await;
}

Add a database

use velvet::prelude::*;

fn index(Extension(db): Extension<Pool<Postgres>>) -> &'static str {
    let result = query_as!(String, "select 1").fetch_one(&db).await?;
    result
}

#[tokio::main]
async fn main() {
    let db = database().await;

    App::new()
        .router(Router::new().route("/", get(index))
        .inject(db)
        .start()
        .await;
}

Support for static files

Example:

use velvet::prelude::*;

#[tokio::main]
async fn main() {
    #[derive(RustEmbed)]
    #[folder = "statics"]
    struct S;

    App::new()
        .statics::<S>()
        .start()
        .await;
}

Where to find...

  • Status (no-op): http GET /status/liveness
  • Metrics: http GET /metrics/prometheus

ENV vars

  • SERVER_BIND: ip for which to listen on
  • SERVER_PORT: [number] port for which to listen on
  • SENTRY_URL: full url for sending data to sentry, if present
  • DATABASE_URL: postgres://user:pass@host:port/database (if database used)
  • DATABASE_MAX_CONNECTIONS: [number] (default 1)
  • STRUCTURED_LOGGING: true|false (default false)
  • SENTRY_URL: url inclusive of key for sending telemtry to sentry

About

No description, website, or topics provided.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages