43 lines
975 B
Rust
43 lines
975 B
Rust
use std::{
|
|
sync::{Arc, Mutex},
|
|
net::SocketAddr,
|
|
str::FromStr,
|
|
};
|
|
use axum::{
|
|
Router,
|
|
routing::get, Extension,
|
|
};
|
|
use tower_http::services::ServeDir;
|
|
use diesel::{Connection, pg::PgConnection};
|
|
|
|
use libticker::config::Config;
|
|
mod index;
|
|
|
|
#[derive(Clone)]
|
|
pub struct AppState {
|
|
pub db: Arc<Mutex<PgConnection>>,
|
|
pub config: Config,
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
let config = Config::read_yaml_file("config.yaml");
|
|
let http_bind = SocketAddr::from_str(&config.http_bind)
|
|
.expect("http_bind");
|
|
let db = PgConnection::establish(&config.db_url)
|
|
.expect("DB");
|
|
|
|
let state = AppState {
|
|
db: Arc::new(Mutex::new(db)),
|
|
config,
|
|
};
|
|
let app = Router::new()
|
|
.route("/", get(index::index))
|
|
.layer(Extension(state))
|
|
.nest_service("/static", ServeDir::new("static"));
|
|
axum::Server::bind(&http_bind)
|
|
.serve(app.into_make_service())
|
|
.await
|
|
.unwrap();
|
|
}
|