fixed webserver not working

- shared store in main
- multiple tasks for webserver
This commit is contained in:
2025-10-07 17:29:14 +02:00
parent 8cbdf834a1
commit 082f1faba9
5 changed files with 179 additions and 45 deletions

31
src/webserver/app.rs Normal file
View File

@@ -0,0 +1,31 @@
use alloc::rc::Rc;
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, mutex::Mutex};
use picoserve::{AppWithStateBuilder, routing::get};
use crate::{
webserver::{
api::{add_mapping, get_mapping},
assets::Assets,
}, UsedStore,
};
#[derive(Clone)]
pub struct AppState {
pub store: Rc<Mutex<CriticalSectionRawMutex, UsedStore>>,
}
pub struct AppProps;
impl AppWithStateBuilder for AppProps {
type State = AppState;
type PathRouter = impl picoserve::routing::PathRouter<AppState>;
fn build_app(self) -> picoserve::Router<Self::PathRouter, AppState> {
picoserve::Router::from_service(Assets)
.route("/api/mapping", get(get_mapping).post(add_mapping))
// .route(
// "/api/idevent",
// get(move || response::EventStream(Events(self.chan))),
// )
}
}