Files
httpserver/src/main.rs
tomoron a425bfbc67
All checks were successful
build docker container automatically / build (push) Successful in 3m39s
fix background color, start scheduled task tests
2026-04-21 11:41:31 +02:00

98 lines
2.1 KiB
Rust

use dioxus::prelude::*;
use crate::dioxus_fullstack::FullstackContext;
use tracing::Level;
pub mod config;
use async_std::task;
use std::time::Duration;
use crate::components::toast::ToastProvider;
use crate::views::{
Upload,
UploadInfo,
Home,
NotFound
};
#[cfg(feature = "server")]
use crate::config::ServerConfig;
mod components;
mod views;
#[derive(Debug, Clone, Routable, PartialEq)]
#[rustfmt::skip]
enum Route {
#[layout(ErrorLayout)]
#[route("/")]
Home { },
#[route("/upload/:file")]
UploadInfo { file: String },
#[route("/upload")]
Upload { },
#[route("/:..route")]
NotFound { route: Vec<String> },
}
const FAVICON: Asset = asset!("/assets/favicon.ico");
const STYLE_CSS: Asset = asset!("/assets/style.css");
const TAILWIND_CSS: Asset = asset!("/assets/tailwind.css");
fn main() {
#[cfg(feature = "server")]
let _ = ServerConfig::load();
#[cfg(feature = "server")]
task::spawn(scheduled_tasks());
dioxus::logger::init(Level::INFO).expect("failed to init logger");
dioxus::launch(App);
}
async fn scheduled_tasks() {
loop {
task::sleep(Duration::from_secs(1)).await;
// tracing::info!("patate douce");
}
}
#[component]
fn ErrorLayout() -> Element {
rsx! {
ErrorBoundary {
handle_error: move |err: ErrorContext| {
let http_error = FullstackContext::commit_error_status(err.error().unwrap());
match http_error.status {
StatusCode::NOT_FOUND => rsx! { div { "404 - Page not found" } },
_ => rsx! { div { "An unknown error occurred" } },
}
},
Outlet::<Route> {}
}
}
}
#[component]
fn App() -> Element {
rsx! {
document::Link { rel: "icon", href: FAVICON }
document::Link { rel: "stylesheet", href: STYLE_CSS }
document::Link { rel: "stylesheet", href: TAILWIND_CSS }
div {
class: "h-full w-full text-white",
ToastProvider {
Router::<Route> {}
}
}
}
}