2021-05-09 14:17:24 -06:00
|
|
|
#![forbid(unsafe_code)]
|
|
|
|
|
2022-04-12 16:06:19 -06:00
|
|
|
use std::net::{IpAddr, SocketAddr};
|
2021-04-20 10:07:11 -06:00
|
|
|
|
2022-04-12 16:06:19 -06:00
|
|
|
use axum::Server;
|
|
|
|
use database::Postgres;
|
|
|
|
use eyre::{Context, Result};
|
2021-04-20 10:07:11 -06:00
|
|
|
|
|
|
|
use crate::settings::Settings;
|
|
|
|
|
2021-04-20 14:53:07 -06:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
|
|
|
|
2021-04-20 10:07:11 -06:00
|
|
|
pub mod auth;
|
|
|
|
pub mod database;
|
|
|
|
pub mod handlers;
|
|
|
|
pub mod models;
|
|
|
|
pub mod router;
|
2021-04-20 14:53:07 -06:00
|
|
|
pub mod settings;
|
2021-04-20 10:07:11 -06:00
|
|
|
|
2022-04-12 16:06:19 -06:00
|
|
|
pub async fn launch(settings: Settings, host: String, port: u16) -> Result<()> {
|
2021-04-20 10:07:11 -06:00
|
|
|
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))?;
|
2021-04-20 10:07:11 -06:00
|
|
|
|
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?;
|
2021-04-20 10:07:11 -06:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|