@@ 6,7 6,10 @@
* See LICENSE for licensing information.
*/
-use actix_web::{get, middleware::Logger, web, App, HttpResponse, HttpServer, Responder};
+use actix_session::{storage::RedisActorSessionStore, SessionMiddleware};
+use actix_web::{
+ cookie::Key, get, middleware::Logger, web, App, HttpResponse, HttpServer, Responder,
+};
use diesel::{
self,
@@ 52,10 55,20 @@ async fn main() -> std::io::Result<()> {
log::info!("running migrations");
run_migrations(&mut pg_pool.get().unwrap());
+ let redis_url = std::env::var("LAURELIN_REDIS_URL").expect("LAURELIN_REDIS_URL");
+ let cookie_key = std::env::var("LAURELIN_COOKIE_KEY").expect("LAURELIN_COOKIE_KEY");
+
HttpServer::new(move || {
App::new()
.app_data(web::Data::new(pg_pool.clone()))
.wrap(Logger::new(log_format))
+ .wrap(
+ SessionMiddleware::builder(
+ RedisActorSessionStore::new(&redis_url),
+ Key::from(cookie_key.as_bytes()),
+ )
+ .build(),
+ )
.service(ping)
.service(handlers::info)
.service(handlers::user::create)