atuin/atuin-server/src/lib.rs

34 lines
732 B
Rust
Raw Normal View History

#![forbid(unsafe_code)]
2022-04-12 16:06:19 -06:00
use std::net::{IpAddr, SocketAddr};
2022-04-12 16:06:19 -06:00
use axum::Server;
use database::Postgres;
use eyre::{Context, Result};
use crate::settings::Settings;
pub mod auth;
pub mod calendar;
pub mod database;
pub mod handlers;
pub mod models;
pub mod router;
pub mod settings;
2022-04-12 16:06:19 -06:00
pub async fn launch(settings: Settings, host: String, port: u16) -> Result<()> {
let host = host.parse::<IpAddr>()?;
2022-04-12 16:06:19 -06:00
let postgres = Postgres::new(settings.db_uri.as_str())
.await
.wrap_err_with(|| format!("failed to connect to db: {}", settings.db_uri))?;
2022-04-12 16:06:19 -06:00
let r = router::router(postgres, settings);
Server::bind(&SocketAddr::new(host, port))
.serve(r.into_make_service())
.await?;
Ok(())
}