2026-02-26 08:31:48 -05:00
|
|
|
use std::error::Error;
|
2026-02-23 09:57:22 -05:00
|
|
|
|
2026-02-26 08:31:48 -05:00
|
|
|
use axum::{Router, routing::get};
|
|
|
|
|
use log::{debug, info};
|
2026-02-17 09:34:22 -05:00
|
|
|
use tower_http::services::ServeDir;
|
|
|
|
|
|
2026-02-26 08:31:48 -05:00
|
|
|
pub mod devices;
|
|
|
|
|
pub mod notifications;
|
|
|
|
|
pub mod utils;
|
2026-02-25 15:58:32 -05:00
|
|
|
|
2026-02-23 09:57:22 -05:00
|
|
|
pub async fn serve() -> Result<(), Box<dyn Error>> {
|
2026-02-17 09:34:22 -05:00
|
|
|
info!("Starting web server");
|
|
|
|
|
let static_files = ServeDir::new("./web");
|
|
|
|
|
|
|
|
|
|
let router = Router::new()
|
|
|
|
|
.route("/", get(|| async { "hello" }))
|
2026-02-26 08:31:48 -05:00
|
|
|
.route("/api/devices", get(devices::list_devices))
|
|
|
|
|
.route("/api/notifications", get(notifications::list_notifications))
|
|
|
|
|
.route(
|
|
|
|
|
"/api/notifications/{id}",
|
|
|
|
|
get(notifications::read_notification),
|
|
|
|
|
)
|
2026-02-23 19:45:19 -05:00
|
|
|
.route(
|
|
|
|
|
"/api/notifications/{id}/read_without_flagging",
|
2026-02-26 08:31:48 -05:00
|
|
|
get(notifications::read_notification_without_flagging),
|
2026-02-23 19:45:19 -05:00
|
|
|
)
|
2026-02-17 09:34:22 -05:00
|
|
|
.nest_service("/web", static_files);
|
2026-02-23 09:57:22 -05:00
|
|
|
info!("Web server starting at http://0.0.0.0:3000");
|
2026-02-17 09:34:22 -05:00
|
|
|
// Start the server
|
2026-02-23 09:57:22 -05:00
|
|
|
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
|
|
|
|
|
|
|
|
|
|
debug!("Web server bound to IP and port");
|
|
|
|
|
|
|
|
|
|
axum::serve(listener, router).await?;
|
2026-02-17 09:34:22 -05:00
|
|
|
Ok(())
|
|
|
|
|
}
|