49 lines
1.4 KiB
Rust
49 lines
1.4 KiB
Rust
//! Main entry point for the HeroDB server
|
|
//!
|
|
//! This file serves as the entry point for the HeroDB server,
|
|
//! which provides a web API for accessing HeroDB functionality.
|
|
|
|
use std::path::PathBuf;
|
|
|
|
// We need tokio for the async runtime
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
// Print a welcome message
|
|
println!("Starting HeroDB server...");
|
|
|
|
// Set up default values
|
|
let host = "127.0.0.1";
|
|
let port = 3002;
|
|
|
|
// Create a temporary directory for the database
|
|
let db_path = match create_temp_dir() {
|
|
Ok(path) => {
|
|
println!("Using temporary DB path: {:?}", path);
|
|
path
|
|
}
|
|
Err(e) => {
|
|
eprintln!("Error creating temporary directory: {}", e);
|
|
return Err(e.into());
|
|
}
|
|
};
|
|
|
|
println!("Starting server on {}:{}", host, port);
|
|
println!("API Documentation: http://{}:{}/docs", host, port);
|
|
|
|
// Start the server
|
|
herodb::server::start_server(db_path, host, port).await?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
/// Creates a simple temporary directory for the database
|
|
fn create_temp_dir() -> std::io::Result<PathBuf> {
|
|
let temp_dir = std::env::temp_dir();
|
|
let random_name = format!("herodb-{}", std::time::SystemTime::now()
|
|
.duration_since(std::time::UNIX_EPOCH)
|
|
.unwrap()
|
|
.as_millis());
|
|
let path = temp_dir.join(random_name);
|
|
std::fs::create_dir_all(&path)?;
|
|
Ok(path)
|
|
} |