DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

b8f294adb75c41a5d52d72f09da6963d3ae00826 — Jonni Liljamo 1 year, 7 months ago b9cd32a
feat(api): init redis session backend
1 files changed, 14 insertions(+), 1 deletions(-)

M api/src/main.rs
M api/src/main.rs => api/src/main.rs +14 -1
@@ 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)