First step in moving sessions into the database.

This commit is contained in:
Jeff Baskin 2022-06-24 15:36:05 -04:00
parent ea0503defd
commit 4bd1a91704
4 changed files with 15 additions and 5 deletions

2
Cargo.lock generated
View File

@ -1035,7 +1035,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]] [[package]]
name = "morethantext_web" name = "morethantext"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"async-std", "async-std",

View File

@ -1,5 +1,5 @@
[package] [package]
name = "morethantext_web" name = "morethantext"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"

8
src/lib.rs Normal file
View File

@ -0,0 +1,8 @@
#[derive(Clone)]
pub struct Database {}
impl Database {
pub fn new() -> Self {
Self {}
}
}

View File

@ -1,3 +1,4 @@
use morethantext::Database;
use tide::{ use tide::{
http::StatusCode, http::StatusCode,
sessions::{MemoryStore, SessionMiddleware}, sessions::{MemoryStore, SessionMiddleware},
@ -17,8 +18,9 @@ async fn main() -> tide::Result<()> {
Ok(()) Ok(())
} }
async fn app_setup() -> tide::Server<()> { async fn app_setup() -> tide::Server<Database> {
let mut app = tide::new(); let db = Database::new();
let mut app = tide::with_state(db);
app.at("/").get(home); app.at("/").get(home);
app.with( app.with(
SessionMiddleware::new(MemoryStore::new(), b"361f953f-56ba-45e6-86ab-9efbf61b745d") SessionMiddleware::new(MemoryStore::new(), b"361f953f-56ba-45e6-86ab-9efbf61b745d")
@ -27,7 +29,7 @@ async fn app_setup() -> tide::Server<()> {
return app; return app;
} }
async fn home(_req: Request<()>) -> tide::Result { async fn home(_req: Request<Database>) -> tide::Result {
let mut res = Response::new(StatusCode::Ok); let mut res = Response::new(StatusCode::Ok);
res.set_body("<!DOCTYPE html> res.set_body("<!DOCTYPE html>
<html> <html>