Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeMathWalker committed Aug 26, 2024
1 parent 6ae70de commit 764af38
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
14 changes: 11 additions & 3 deletions examples/session-cookie/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
actix-web = { version = "4", default-features = false, features = ["cookies", "secure-cookies", "macros"] }
actix-web-flash-messages = { path = "../../actix-web-flash-messages", features = ["sessions"] }
actix-session = { version = "0.6.2", default-features = false, features = ["cookie-session"] }
actix-web = { version = "4", default-features = false, features = [
"cookies",
"secure-cookies",
"macros",
] }
actix-web-flash-messages = { path = "../../actix-web-flash-messages", features = [
"sessions",
] }
actix-session = { version = "0.10", default-features = false, features = [
"cookie-session",
] }
14 changes: 11 additions & 3 deletions examples/session-redis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
actix-web = { version = "4", default-features = false, features = ["cookies", "secure-cookies", "macros"] }
actix-web-flash-messages = { path = "../../actix-web-flash-messages", features = ["sessions"] }
actix-session = { version = "0.6.2", default-features = false, features = ["redis-actor-session"] }
actix-web = { version = "4", default-features = false, features = [
"cookies",
"secure-cookies",
"macros",
] }
actix-web-flash-messages = { path = "../../actix-web-flash-messages", features = [
"sessions",
] }
actix-session = { version = "0.10", default-features = false, features = [
"redis-session",
] }
actix-redis = { version = "0.11.0" }
13 changes: 8 additions & 5 deletions examples/session-redis/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use actix_session::storage::RedisActorSessionStore;
use actix_session::storage::RedisSessionStore;
use actix_session::SessionMiddleware;
use actix_web::cookie::{Key, SameSite};
use actix_web::{http, web, App, HttpResponse, HttpServer, Responder};
Expand Down Expand Up @@ -36,10 +36,10 @@ fn build_message_framework() -> FlashMessagesFramework {
}

fn build_session_storage(
redis_address: String,
store: RedisSessionStore,
key: Key,
) -> SessionMiddleware<RedisActorSessionStore> {
SessionMiddleware::builder(RedisActorSessionStore::new(&redis_address), key)
) -> SessionMiddleware<RedisSessionStore> {
SessionMiddleware::builder(store, key)
.cookie_http_only(true)
.cookie_secure(true)
.cookie_same_site(SameSite::Strict)
Expand All @@ -50,6 +50,9 @@ fn build_session_storage(
async fn main() {
// This will usually come from configuration!
let key = Key::generate();
let store = RedisSessionStore::new("redis://127.0.0.1:6379")
.await
.unwrap();

HttpServer::new(move || {
App::new()
Expand All @@ -58,7 +61,7 @@ async fn main() {
.wrap(build_message_framework())
// You need a running Redis on port 6379
// You can use `docker run -d -p 6379:6379 redis`
.wrap(build_session_storage("127.0.0.1:6379".into(), key.clone()))
.wrap(build_session_storage(store.clone(), key.clone()))
.route("/show", web::get().to(show))
.route("/set", web::get().to(set))
})
Expand Down

0 comments on commit 764af38

Please sign in to comment.