First step in moving sessions into the database.
This commit is contained in:
		
							
								
								
									
										8
									
								
								src/lib.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/lib.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
#[derive(Clone)]
 | 
			
		||||
pub struct Database {}
 | 
			
		||||
 | 
			
		||||
impl Database {
 | 
			
		||||
    pub fn new() -> Self {
 | 
			
		||||
        Self {}
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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<Database> {
 | 
			
		||||
    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<Database>) -> tide::Result {
 | 
			
		||||
    let mut res = Response::new(StatusCode::Ok);
 | 
			
		||||
    res.set_body("<!DOCTYPE html>
 | 
			
		||||
<html>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user