chore: first commit
This commit is contained in:
commit
4f811d88f2
30 changed files with 4301 additions and 0 deletions
60
src/main.rs
Normal file
60
src/main.rs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#![allow(unused)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
use axum_htmx::AutoVaryLayer;
|
||||
use compendium::config::Config;
|
||||
use compendium::{config, router, AppState, Error, Link, Result, Tx};
|
||||
use minijinja::{Environment, Value};
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
use sqlx::PgPool;
|
||||
use std::env;
|
||||
use std::sync::Arc;
|
||||
use tower_http::trace::TraceLayer;
|
||||
use tracing::info;
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
let config = Config::new("./config.toml".into())?;
|
||||
|
||||
// Logs
|
||||
tracing_subscriber::registry()
|
||||
.with(
|
||||
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| {
|
||||
format!("{}=debug,tower_http=debug", env!("CARGO_CRATE_NAME")).into()
|
||||
}),
|
||||
)
|
||||
.with(tracing_subscriber::fmt::layer())
|
||||
.init();
|
||||
|
||||
let mut tmpl_env = Environment::new();
|
||||
|
||||
minijinja_embed::load_templates!(&mut tmpl_env);
|
||||
|
||||
info!("Connecting to database {}", config.db);
|
||||
|
||||
let pool = PgPoolOptions::new()
|
||||
.max_connections(5)
|
||||
.connect(&config.db.generate_db_string(false)?)
|
||||
.await?;
|
||||
|
||||
sqlx::migrate!("./migrations").run(&pool).await?;
|
||||
|
||||
let (tx_state, tx_layer) = Tx::setup(pool);
|
||||
|
||||
let app = router::new()
|
||||
.layer(TraceLayer::new_for_http().on_request(()))
|
||||
.layer(tx_layer)
|
||||
.layer(AutoVaryLayer)
|
||||
.with_state(AppState::new(tmpl_env, tx_state));
|
||||
|
||||
// Add hot reload only on dev mode
|
||||
#[cfg(debug_assertions)]
|
||||
let app = app.layer(tower_livereload::LiveReloadLayer::new());
|
||||
|
||||
let listener = tokio::net::TcpListener::bind(config.addr).await?;
|
||||
info!("listening on {}", listener.local_addr()?);
|
||||
|
||||
axum::serve(listener, app).await?;
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue