about summary refs log tree commit diff
path: root/src/main.rs
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2021-05-04 17:05:51 +0300
committerVika <vika@fireburn.ru>2021-05-04 17:07:25 +0300
commit08c09aaa055c05228855eed8cded9fdfe4939c0f (patch)
tree792ba1d2a3b3af7a837135aa90620d8f689d7ebd /src/main.rs
downloadkittybox-08c09aaa055c05228855eed8cded9fdfe4939c0f.tar.zst
Initial commit
Working features:
 - Sending posts from the database
 - Reading posts from the database
 - Responding with MF2-JSON (only in debug mode!)
 - Not locking the database when not needed
 - All database actions are atomic (except for a small race where UIDs
   can clash, but that's not gonna happen often)

TODOs:
 - Send webmentions
 - Send syndication requests
 - Send WebSub notifications
 - Make tombstones for deleted posts (update adding dt-deleted)
 - Rich reply contexts (possibly on the frontend part?)
 - Frontend?
 - Fix UID race

Code maintenance TODOs:
 - Split the database module
 - Finish implementing the in-memory test database
 - Make RedisDatabase unit tests launch their own Redis instances (see
   redis-rs/tests/support/mod.rs for more info)
 - Write more unit-tests!!!
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..3d0831e
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,48 @@
+use std::env;
+use log::{error,info,debug};
+use env_logger;
+use surf::Url;
+use kittybox_micropub as micropub;
+
+#[async_std::main]
+async fn main() -> Result<(), std::io::Error> {
+    // TODO json logging in the future?
+    let logger_env = env_logger::Env::new().filter_or("RUST_LOG", "info");
+    env_logger::init_from_env(logger_env);
+
+    info!("Starting the Micropub server...");
+
+    let redis_uri: String;
+    match env::var("REDIS_URI") {
+        Ok(val) => {
+            debug!("Redis connection: {}", val);
+            redis_uri = val
+        },
+        Err(_) => {
+            error!("REDIS_URI is not set, cannot find a database");
+            std::process::exit(1);
+        }
+    };
+    let token_endpoint: Url;
+    match env::var("TOKEN_ENDPOINT") {
+        Ok(val) => {
+            debug!("Token endpoint: {}", val);
+            match Url::parse(&val) {
+                Ok(val) => token_endpoint = val,
+                _ => {
+                    error!("Token endpoint URL cannot be parsed, aborting.");
+                    std::process::exit(1)
+                }
+            }
+        }
+        Err(_) => {
+            error!("TOKEN_ENDPOINT is not set, will not be able to authorize users!");
+            std::process::exit(1)
+        }
+    }
+    let media_endpoint: Option<String> = env::var("MEDIA_ENDPOINT").ok();
+
+    let host = env::var("SERVE_AT").ok().unwrap_or("0.0.0.0:8080".to_string());
+    let app = micropub::get_app_with_redis(token_endpoint, redis_uri, media_endpoint).await;
+    app.listen(host).await
+}
\ No newline at end of file