blob: a3876571bd09fd480f5df5e060ca6bfd10718b89 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
use silmataivas::app_with_state;
use sqlx::SqlitePool;
use std::env;
use std::net::SocketAddr;
use std::sync::Arc;
use tokio::fs;
#[tokio::main]
async fn main() {
// Set up database path
let db_path =
env::var("DATABASE_URL").unwrap_or_else(|_| "sqlite://./data/silmataivas.db".to_string());
// Ensure data directory exists
let _ = fs::create_dir_all("./data").await;
// Connect to SQLite
let pool = SqlitePool::connect(&db_path)
.await
.expect("Failed to connect to DB");
let app = app_with_state(Arc::new(pool));
let addr = SocketAddr::from(([0, 0, 0, 0], 4000));
let listener = tokio::net::TcpListener::bind(addr)
.await
.expect("Failed to bind address");
println!("Listening on {}", listener.local_addr().unwrap());
axum::serve(listener, app).await.unwrap();
}
|