Implement support for serving webui
This commit is contained in:
@@ -4,18 +4,15 @@ mod utils;
|
||||
|
||||
use utils::init_database;
|
||||
use anyhow::Result;
|
||||
use axum::{
|
||||
routing::{delete, get, post, put},
|
||||
Router,
|
||||
};
|
||||
use axum::{routing::{delete, get, post, put}, Router};
|
||||
use routes::{admin, auth as auth_routes, machines, setup};
|
||||
use tower_http::cors::CorsLayer;
|
||||
use tower_http::{cors::CorsLayer, services::{ServeDir, ServeFile}};
|
||||
use std::path::Path;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
let pool = init_database().await?;
|
||||
|
||||
let app = Router::new()
|
||||
let api_routes = Router::new()
|
||||
.route("/setup/status", get(setup::get_setup_status))
|
||||
.route("/setup/init", post(setup::init_setup))
|
||||
|
||||
@@ -35,10 +32,20 @@ async fn main() -> Result<()> {
|
||||
|
||||
.with_state(pool);
|
||||
|
||||
let dist_path = "../dist";
|
||||
let app = Router::new()
|
||||
.nest("/api", api_routes)
|
||||
.nest_service("/assets", ServeDir::new(format!("{}/assets", dist_path)))
|
||||
.route_service("/", ServeFile::new(format!("{}/index.html", dist_path)))
|
||||
.fallback_service(ServeFile::new(format!("{}/index.html", dist_path)))
|
||||
.layer(CorsLayer::permissive());
|
||||
|
||||
if !Path::new(dist_path).exists() {
|
||||
println!("Warning: dist directory not found at {}", dist_path);
|
||||
}
|
||||
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:8379").await?;
|
||||
println!("Server running on http://0.0.0.0:8379");
|
||||
|
||||
axum::serve(listener, app).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user