about summary refs log tree commit diff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2021-05-09 16:51:24 +0300
committerVika <vika@fireburn.ru>2021-05-09 16:51:24 +0300
commit22f5a47425dc677294b6ae9ebf7ffe949e9dc903 (patch)
tree9c3b169c413dde25ceacd9d68bdc4f31e08fd6b3 /src/lib.rs
parentaf8d55312ef99357ab23608eef6bf7fa40635828 (diff)
Added a frontend to the application. TODO: Login, alternative themes, built-in Micropub capabilities when logged in
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs41
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
 }