From 696ae495aca701c3431710e5dfc03e15aba2f74e Mon Sep 17 00:00:00 2001 From: Vika Date: Mon, 17 May 2021 04:12:48 +0300 Subject: Refactoring, easter egg, healthcheck endpoint, support for rel= indieweb APIs and preparation for onboarding --- src/lib.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/lib.rs') 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 @@ -14,6 +13,7 @@ where StorageBackend: database::Storage + Send + Sync + 'static { token_endpoint: surf::Url, + authorization_endpoint: surf::Url, media_endpoint: Option, http_client: surf::Client, storage: StorageBackend @@ -27,21 +27,27 @@ fn equip_app(mut app: App) -> App 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) -> App { +pub async fn get_app_with_redis(token_endpoint: surf::Url, authorization_endpoint: surf::Url, redis_uri: String, media_endpoint: Option) -> App { 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(), }); -- cgit 1.4.1