diff options
| author | Conrad Ludgate <conrad.ludgate@truelayer.com> | 2022-04-12 23:06:19 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-12 23:06:19 +0100 |
| commit | a95018cc9039851e707973bc19faf907132ae4f3 (patch) | |
| tree | e135f1da64c5d020f336d437f83a333298861ca0 /atuin-server/src/lib.rs | |
| parent | fix env config parsing (#295) (diff) | |
| download | atuin-a95018cc9039851e707973bc19faf907132ae4f3.zip | |
goodbye warp, hello axum (#296)
Diffstat (limited to 'atuin-server/src/lib.rs')
| -rw-r--r-- | atuin-server/src/lib.rs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/atuin-server/src/lib.rs b/atuin-server/src/lib.rs index e4858811..ca0aa11c 100644 --- a/atuin-server/src/lib.rs +++ b/atuin-server/src/lib.rs @@ -1,8 +1,10 @@ #![forbid(unsafe_code)] -use std::net::IpAddr; +use std::net::{IpAddr, SocketAddr}; -use eyre::Result; +use axum::Server; +use database::Postgres; +use eyre::{Context, Result}; use crate::settings::Settings; @@ -19,14 +21,18 @@ pub mod models; pub mod router; pub mod settings; -pub async fn launch(settings: &Settings, host: String, port: u16) -> Result<()> { - // routes to run: - // index, register, add_history, login, get_user, sync_count, sync_list +pub async fn launch(settings: Settings, host: String, port: u16) -> Result<()> { let host = host.parse::<IpAddr>()?; - let r = router::router(settings).await?; + let postgres = Postgres::new(settings.db_uri.as_str()) + .await + .wrap_err_with(|| format!("failed to connect to db: {}", settings.db_uri))?; - warp::serve(r).run((host, port)).await; + let r = router::router(postgres, settings); + + Server::bind(&SocketAddr::new(host, port)) + .serve(r.into_make_service()) + .await?; Ok(()) } |
