dermy-api/src/lib.rs

48 lines
989 B
Rust
Raw Normal View History

2024-06-06 18:21:12 +00:00
mod account;
mod model;
2024-06-07 01:24:42 +00:00
use anyhow::Result;
2024-06-07 14:30:16 +00:00
use axum::response::{IntoResponse, Response};
2024-06-07 21:29:49 +00:00
use axum_session::{SessionConfig, SessionStore};
2024-06-07 01:24:42 +00:00
use axum_session_mongo::SessionMongoPool;
2024-06-07 14:30:16 +00:00
use http::StatusCode;
2024-06-07 21:29:49 +00:00
use mongodb::Client;
2024-06-07 01:24:42 +00:00
pub async fn run() -> Result<()> {
2024-06-07 21:29:49 +00:00
let app = router();
2024-06-07 17:59:35 +00:00
2024-06-07 21:29:49 +00:00
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
2024-06-07 01:24:42 +00:00
Ok(())
2024-06-06 18:25:03 +00:00
}
fn router() -> axum::Router {
2024-06-06 18:21:12 +00:00
axum::Router::new()
.nest("/account", account::router())
2024-06-07 17:59:35 +00:00
//.nest("/predict", model::router())
2024-06-06 18:21:12 +00:00
}
2024-06-07 01:24:42 +00:00
2024-06-07 14:30:16 +00:00
struct AppError(anyhow::Error);
impl IntoResponse for AppError {
fn into_response(self) -> Response {
(
StatusCode::INTERNAL_SERVER_ERROR,
format!("Something went wrong: {}", self.0),
)
.into_response()
}
}
impl<E> From<E> for AppError
where
E: Into<anyhow::Error>,
{
fn from(err: E) -> Self {
Self(err.into())
}
}