session cookie store init

This commit is contained in:
mtrx 2024-12-28 01:55:22 +01:00
parent b61c62a806
commit 7ba1605456
5 changed files with 869 additions and 381 deletions

View file

@ -10,11 +10,16 @@ extern crate serde_derive;
extern crate tera;
use actix_files as fs;
use actix_session::{storage::CookieSessionStore, SessionMiddleware};
use actix_web::cookie::Key;
use actix_web::{middleware::Logger, web::Data, App, HttpServer};
use config::CONFIG;
use env_logger::Env;
use once_cell::sync::Lazy;
use tera::Tera;
static SESSION_COOKIE_SECRET_KEY: Lazy<Key> = Lazy::new(|| Key::generate());
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(move || {
@ -25,6 +30,10 @@ async fn main() -> std::io::Result<()> {
env_logger::Builder::from_env(Env::default().default_filter_or("debug"));
App::new()
.wrap(SessionMiddleware::new(
CookieSessionStore::default(),
SESSION_COOKIE_SECRET_KEY.clone(),
))
.app_data(Data::new(tera))
.service(routes::about)
.service(routes::blog)