about summary refs log tree commit diff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2021-05-17 04:12:48 +0300
committerVika <vika@fireburn.ru>2021-05-17 04:12:48 +0300
commit696ae495aca701c3431710e5dfc03e15aba2f74e (patch)
tree3b58d7cb23a8edd5fdb7121ab420ed60a9af64cb /src/lib.rs
parent3dbe61f57873881dfbf5da8a335762a0e1dccbb5 (diff)
Refactoring, easter egg, healthcheck endpoint, support for rel= indieweb APIs and preparation for onboarding
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 949b9ac..ed30b94 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -6,7 +6,6 @@ mod micropub;
 mod frontend;
 
 use crate::indieauth::IndieAuthMiddleware;
-use crate::micropub::{get_handler,post_handler};
 
 #[derive(Clone)]
 pub struct ApplicationState<StorageBackend>
@@ -14,6 +13,7 @@ where
     StorageBackend: database::Storage + Send + Sync + 'static
 {
     token_endpoint: surf::Url,
+    authorization_endpoint: surf::Url,
     media_endpoint: Option<String>,
     http_client: surf::Client,
     storage: StorageBackend
@@ -27,21 +27,27 @@ fn equip_app<Storage>(mut app: App<Storage>) -> App<Storage>
 where
     Storage: database::Storage + Send + Sync + Clone
 {
-    app.at("/micropub").with(IndieAuthMiddleware::new()).get(get_handler).post(post_handler);
+    app.at("/micropub").with(IndieAuthMiddleware::new())
+        .get(micropub::get_handler)
+        .post(micropub::post_handler);
     // The Micropub client. It'll start small, but could grow into something full-featured!
     app.at("/micropub/client").get(|_: Request<_>| async move {
         Ok(Response::builder(200).body(MICROPUB_CLIENT).content_type("text/html").build())
     });
-    app.at("/").with(frontend::ErrorHandlerMiddleware {}).get(frontend::mainpage);
+    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.at("/coffee").with(frontend::ErrorHandlerMiddleware {}).get(frontend::coffee);
+    app.at("/health").get(|_| async { Ok("OK") });
 
     app
 }
 
-pub async fn get_app_with_redis(token_endpoint: surf::Url, redis_uri: String, media_endpoint: Option<String>) -> App<database::RedisStorage> {
+pub async fn get_app_with_redis(token_endpoint: surf::Url, authorization_endpoint: surf::Url, redis_uri: String, media_endpoint: Option<String>) -> App<database::RedisStorage> {
     let app = tide::with_state(ApplicationState { 
         token_endpoint, media_endpoint,
+        authorization_endpoint,
         storage: database::RedisStorage::new(redis_uri).await.unwrap(),
         http_client: surf::Client::new(),
     });
@@ -55,6 +61,7 @@ pub async fn get_app_with_test_redis(token_endpoint: surf::Url) -> (database::Re
     let backend = database::RedisStorage::new(redis_instance.uri().to_string()).await.unwrap();
     let app = tide::with_state(ApplicationState {
         token_endpoint, media_endpoint: None,
+        authorization_endpoint: Url::parse("https://indieauth.com/auth"),
         storage: backend.clone(),
         http_client: surf::Client::new(),
     });