basic backend init
This commit is contained in:
27
backend/src/server.rs
Normal file
27
backend/src/server.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use std::{env, error::Error};
|
||||
|
||||
use axum::Router;
|
||||
use tokio::net::TcpListener;
|
||||
use tower_http::services::ServeDir;
|
||||
|
||||
pub(super) async fn start() -> Result<(), Box<dyn Error>> {
|
||||
let mut app = Router::new();
|
||||
|
||||
if !cfg!(debug_assertions) {
|
||||
let frontend_path = env::var("STATIC_FRONTEND_DIR").unwrap_or("./frontend".to_string());
|
||||
let frontend_service = ServeDir::new(frontend_path);
|
||||
|
||||
log::debug!("Registering static frontend");
|
||||
app = app.fallback_service(frontend_service);
|
||||
}
|
||||
|
||||
let addr = env::var("BIND_ADDRESS").unwrap_or("127.0.0.1:8080".to_string());
|
||||
|
||||
let listener = TcpListener::bind(&addr).await?;
|
||||
|
||||
log::info!("Listening on {}", addr);
|
||||
|
||||
axum::serve(listener, app).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user