Added frontend static assets and web server to rust backend

This commit is contained in:
rzuasti
2026-02-12 21:46:50 -05:00
parent f3cf3ebec1
commit ec951f9a89
34 changed files with 166314 additions and 7 deletions
+7 -6
View File
@@ -5,6 +5,7 @@ use rusqlite::Connection;
use std::net::SocketAddr;
use std::sync::{Arc, Mutex};
use tokio::time::{self, Duration, sleep};
use tower_http::services::ServeDir;
mod db;
mod device_finders;
@@ -40,18 +41,18 @@ async fn main() -> Result<(), String> {
async fn web_server() -> Result<(), String> {
info!("Starting web server");
let app = Router::new().route("/", get(root));
let static_files = ServeDir::new("./web");
let router = Router::new()
.route("/", get(|| async { "hello" }))
.nest_service("/web", static_files);
info!("Server running at http://0.0.0.0:3000");
// Start the server
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
axum::serve(listener, router).await.unwrap();
Ok(())
}
async fn root() -> &'static str {
"Welcome to the Rust Web Server!"
}
async fn scanner() -> Result<(), String> {
// Get database connection - thread protected
let db_conn = Arc::new(Mutex::new(db::init_db().unwrap()));