diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 41 |
1 files changed, 4 insertions, 37 deletions
diff --git a/src/lib.rs b/src/lib.rs index c422fea..949b9ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,12 +1,9 @@ -#[cfg(debug_assertions)] -use log::info; -#[cfg(debug_assertions)] -use serde::Deserialize; use tide::{Request, Response}; mod database; mod indieauth; mod micropub; +mod frontend; use crate::indieauth::IndieAuthMiddleware; use crate::micropub::{get_handler,post_handler}; @@ -26,15 +23,6 @@ type App<Storage> = tide::Server<ApplicationState<Storage>>; static MICROPUB_CLIENT: &[u8] = include_bytes!("./index.html"); -#[cfg(debug_assertions)] -#[derive(Deserialize)] -struct Mf2JsonQuery { - url: String, - limit: usize, - user: Option<String>, - after: Option<String> -} - fn equip_app<Storage>(mut app: App<Storage>) -> App<Storage> where Storage: database::Storage + Send + Sync + Clone @@ -44,30 +32,9 @@ where app.at("/micropub/client").get(|_: Request<_>| async move { Ok(Response::builder(200).body(MICROPUB_CLIENT).content_type("text/html").build()) }); - #[cfg(debug_assertions)] - info!("Outfitting app with the debug function"); - #[cfg(debug_assertions)] - app.at("/mf2-json").get(|req: Request<ApplicationState<Storage>>| async move { - info!("DEBUG FUNCTION: Reading MF2-JSON"); - let backend = &req.state().storage; - let query = req.query::<Mf2JsonQuery>()?; - match backend.read_feed_with_limit(&query.url, &query.after, query.limit, &query.user).await { - Ok(result) => match result { - Some(post) => Ok(Response::builder(200).body(post).build()), - None => Ok(Response::builder(404).build()) - }, - Err(err) => match err.kind() { - database::ErrorKind::PermissionDenied => { - if query.user.is_some() { - Ok(Response::builder(403).build()) - } else { - Ok(Response::builder(401).build()) - } - } - _ => Ok(Response::builder(500).body(serde_json::json!({"error": "database_error", "error_description": format!("{}", err)})).build()) - } - } - }); + app.at("/").with(frontend::ErrorHandlerMiddleware {}).get(frontend::mainpage); + app.at("/static/*path").with(frontend::ErrorHandlerMiddleware {}).get(frontend::handle_static); + app.at("/*path").with(frontend::ErrorHandlerMiddleware {}).get(frontend::render_post); app } |