feature/api-setup #4
@@ -1,4 +1,5 @@
|
|||||||
mod config;
|
mod config;
|
||||||
|
mod routes;
|
||||||
mod tasks;
|
mod tasks;
|
||||||
|
|
||||||
use axum::Router;
|
use axum::Router;
|
||||||
@@ -59,7 +60,11 @@ async fn main() {
|
|||||||
|
|
||||||
// build the axum app and run the server...
|
// build the axum app and run the server...
|
||||||
info!("Starting application...");
|
info!("Starting application...");
|
||||||
let app: Router = Router::new();
|
let app: Router = routes::get_root_router(routes::AppState {
|
||||||
|
database_connection: db_connection,
|
||||||
|
service: std::sync::Arc::new(routes::AppService {}),
|
||||||
|
});
|
||||||
|
|
||||||
let address = format!("{}:{}", settings.server.address, settings.server.port);
|
let address = format!("{}:{}", settings.server.address, settings.server.port);
|
||||||
info!("Starting server at http://{}", address);
|
info!("Starting server at http://{}", address);
|
||||||
|
|
||||||
|
|||||||
33
apps/api/src/routes.rs
Normal file
33
apps/api/src/routes.rs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use axum::Router;
|
||||||
|
use migration::sea_orm::DatabaseConnection;
|
||||||
|
|
||||||
|
pub struct AppState {
|
||||||
|
pub database_connection: DatabaseConnection,
|
||||||
|
pub service: Arc<AppService>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct AppService {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_root_router(state: impl Into<Arc<AppState>>) -> Router {
|
||||||
|
let router = Router::new()
|
||||||
|
// TODO: Add routes
|
||||||
|
.with_state(state.into());
|
||||||
|
|
||||||
|
#[allow(clippy::let_and_return)]
|
||||||
|
router
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ensure_state_send_sync() {
|
||||||
|
fn assert_send_sync<T: Send + Sync>() {}
|
||||||
|
assert_send_sync::<AppState>();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user