From 4bd1a91704ece64bcc110a2771b5c2d7ae59201a Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Fri, 24 Jun 2022 15:36:05 -0400 Subject: [PATCH] First step in moving sessions into the database. --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/lib.rs | 8 ++++++++ src/main.rs | 8 +++++--- 4 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 7a0f572..9227e9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1035,7 +1035,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] -name = "morethantext_web" +name = "morethantext" version = "0.1.0" dependencies = [ "async-std", diff --git a/Cargo.toml b/Cargo.toml index eecb8aa..bf26dfd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "morethantext_web" +name = "morethantext" version = "0.1.0" edition = "2021" diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..a9769d7 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,8 @@ +#[derive(Clone)] +pub struct Database {} + +impl Database { + pub fn new() -> Self { + Self {} + } +} diff --git a/src/main.rs b/src/main.rs index b3eaf6e..246e4ee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use morethantext::Database; use tide::{ http::StatusCode, sessions::{MemoryStore, SessionMiddleware}, @@ -17,8 +18,9 @@ async fn main() -> tide::Result<()> { Ok(()) } -async fn app_setup() -> tide::Server<()> { - let mut app = tide::new(); +async fn app_setup() -> tide::Server { + let db = Database::new(); + let mut app = tide::with_state(db); app.at("/").get(home); app.with( SessionMiddleware::new(MemoryStore::new(), b"361f953f-56ba-45e6-86ab-9efbf61b745d") @@ -27,7 +29,7 @@ async fn app_setup() -> tide::Server<()> { return app; } -async fn home(_req: Request<()>) -> tide::Result { +async fn home(_req: Request) -> tide::Result { let mut res = Response::new(StatusCode::Ok); res.set_body("