- Created Cargo.toml with all required dependencies - Implemented health/ready endpoints - Added Docker configuration (production + development) - Configured docker-compose with resource limits - Set up MongoDB service with persistence - Verified build (cargo check passed) - Prepared monorepo structure for mobile/web/shared Next: Phase 2.2 (MongoDB connection and models)
52 lines
1.4 KiB
Rust
52 lines
1.4 KiB
Rust
use axum::{
|
|
routing::get,
|
|
Router,
|
|
response::Json,
|
|
};
|
|
use serde_json::json;
|
|
use tower_http::trace::TraceLayer;
|
|
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
tracing_subscriber::registry()
|
|
.with(
|
|
tracing_subscriber::EnvFilter::try_from_default_env()
|
|
.unwrap_or_else(|_| "normogen_backend=debug,tower_http=debug,axum=debug".into()),
|
|
)
|
|
.with(tracing_subscriber::fmt::layer())
|
|
.init();
|
|
|
|
tracing::info!("Starting Normogen backend server");
|
|
|
|
let app = Router::new()
|
|
.route("/health", get(health_check))
|
|
.route("/ready", get(readiness_check))
|
|
.layer(TraceLayer::new_for_http());
|
|
|
|
let addr = std::net::SocketAddr::from(([0, 0, 0, 0], 8000));
|
|
tracing::info!("Listening on {}", addr);
|
|
|
|
let listener = tokio::net::TcpListener::bind(addr)
|
|
.await
|
|
.expect("Failed to bind address");
|
|
|
|
axum::serve(listener, app)
|
|
.await
|
|
.expect("Server error");
|
|
}
|
|
|
|
async fn health_check() -> Json<serde_json::Value> {
|
|
Json(json!({
|
|
"status": "ok",
|
|
"timestamp": chrono::Utc::now().to_rfc3339(),
|
|
}))
|
|
}
|
|
|
|
async fn readiness_check() -> Json<serde_json::Value> {
|
|
Json(json!({
|
|
"status": "ready",
|
|
"database": "not_connected",
|
|
"timestamp": chrono::Utc::now().to_rfc3339(),
|
|
}))
|
|
}
|