fix(backend): Add debug output to diagnose silent crash
This commit is contained in:
parent
7221a8e280
commit
e5d0ae4fd1
3 changed files with 149 additions and 6 deletions
|
|
@ -19,8 +19,17 @@ use config::Config;
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
dotenv::dotenv().ok();
|
||||
// DEBUG: Print to stderr so we can see it in logs
|
||||
eprintln!("NORMOGEN BACKEND STARTING...");
|
||||
eprintln!("Loading environment variables...");
|
||||
|
||||
// Try to load .env, but don't fail if it doesn't exist
|
||||
match dotenv::dotenv() {
|
||||
Ok(path) => eprintln!("Loaded .env from: {:?}", path),
|
||||
Err(e) => eprintln!("No .env file found (this is OK in Docker): {}", e),
|
||||
}
|
||||
|
||||
eprintln!("Initializing logging...");
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(
|
||||
tracing_subscriber::EnvFilter::try_from_default_env()
|
||||
|
|
@ -28,14 +37,34 @@ async fn main() -> anyhow::Result<()> {
|
|||
)
|
||||
.init();
|
||||
|
||||
let config = Config::from_env()?;
|
||||
eprintln!("Loading configuration...");
|
||||
let config = match Config::from_env() {
|
||||
Ok(cfg) => {
|
||||
tracing::info!("Configuration loaded successfully");
|
||||
eprintln!("Config loaded: DB={}, Port={}", cfg.database.database, cfg.server.port);
|
||||
cfg
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("FATAL: Failed to load configuration: {}", e);
|
||||
return Err(e);
|
||||
}
|
||||
};
|
||||
|
||||
tracing::info!("Connecting to MongoDB at {}", config.database.uri);
|
||||
let db = db::MongoDb::new(&config.database.uri, &config.database.database).await?;
|
||||
tracing::info!("Connected to MongoDB database: {}", config.database.database);
|
||||
eprintln!("Connecting to MongoDB...");
|
||||
let db = match db::MongoDb::new(&config.database.uri, &config.database.database).await {
|
||||
Ok(db) => {
|
||||
tracing::info!("Connected to MongoDB database: {}", config.database.database);
|
||||
eprintln!("MongoDB connection successful");
|
||||
db
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("FATAL: Failed to connect to MongoDB: {}", e);
|
||||
return Err(e);
|
||||
}
|
||||
};
|
||||
|
||||
let health_status = db.health_check().await?;
|
||||
tracing::info!("MongoDB health check: {}", health_status);
|
||||
tracing::info!("MongoDB health check: {}", db.health_check().await?);
|
||||
|
||||
let jwt_service = auth::JwtService::new(config.jwt.clone());
|
||||
|
||||
|
|
@ -45,6 +74,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
config: config.clone(),
|
||||
};
|
||||
|
||||
eprintln!("Building router...");
|
||||
let app = Router::new()
|
||||
// Public endpoints (no auth required)
|
||||
.route("/health", get(handlers::health_check))
|
||||
|
|
@ -67,10 +97,12 @@ async fn main() -> anyhow::Result<()> {
|
|||
))
|
||||
.with_state(app_state);
|
||||
|
||||
eprintln!("Binding to {}:{}...", config.server.host, config.server.port);
|
||||
let listener = tokio::net::TcpListener::bind(&format!("{}:{}", config.server.host, config.server.port))
|
||||
.await?;
|
||||
|
||||
tracing::info!("Server listening on {}:{}", config.server.host, config.server.port);
|
||||
eprintln!("Server is running on http://{}:{}", config.server.host, config.server.port);
|
||||
|
||||
axum::serve(listener, app).await?;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue