1
0
mirror of https://github.com/actix/examples synced 2024-11-27 16:02:57 +01:00

update deps

This commit is contained in:
Rob Ede 2022-10-26 16:51:27 +01:00
parent 83e987ed0c
commit ddda86784a
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
25 changed files with 672 additions and 858 deletions

1380
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,7 @@ members = [
"basics/nested-routing",
"basics/state",
"basics/static-files",
"basics/todo",
# "basics/todo",
"cors/backend",
"data-factory",
"databases/diesel",

View File

@ -5,6 +5,8 @@ edition = "2021"
[dependencies]
actix-web = "4"
actix-identity = "0.4"
actix-identity = "0.5"
actix-session = { version = "0.7", features = ["cookie-session"] }
env_logger = "0.9"
rand = "0.8"

View File

@ -1,23 +1,28 @@
use actix_identity::{CookieIdentityPolicy, Identity, IdentityService};
use actix_web::{middleware, web, App, HttpResponse, HttpServer};
use actix_identity::{Identity, IdentityMiddleware};
use actix_session::{storage::CookieSessionStore, SessionMiddleware};
use actix_web::{
cookie::Key, middleware, web, App, HttpMessage as _, HttpRequest, HttpResponse, HttpServer,
};
use rand::Rng;
async fn index(id: Identity) -> String {
format!(
"Hello {}",
id.identity().unwrap_or_else(|| "Anonymous".to_owned())
id.id().unwrap_or_else(|_| "Anonymous".to_owned())
)
}
async fn login(id: Identity) -> HttpResponse {
id.remember("user1".to_owned());
async fn login(req: HttpRequest) -> HttpResponse {
Identity::login(&req.extensions(), "user1".to_owned()).unwrap();
HttpResponse::Found()
.insert_header(("location", "/"))
.finish()
}
async fn logout(id: Identity) -> HttpResponse {
id.forget();
id.logout();
HttpResponse::Found()
.insert_header(("location", "/"))
.finish()
@ -32,13 +37,16 @@ async fn main() -> std::io::Result<()> {
// private key for every project. Anyone with access to the key can generate
// authentication cookies for any user!
let private_key = rand::thread_rng().gen::<[u8; 32]>();
HttpServer::new(move || {
App::new()
.wrap(IdentityService::new(
CookieIdentityPolicy::new(&private_key)
.name("auth-example")
.secure(false),
))
.wrap(IdentityMiddleware::default())
.wrap(
SessionMiddleware::builder(CookieSessionStore::default(), Key::from(&private_key))
.cookie_name("auth-example".to_owned())
.cookie_secure(false)
.build(),
)
// enable logger - always register Actix Web Logger middleware last
.wrap(middleware::Logger::default())
.service(web::resource("/login").route(web::post().to(login)))

View File

@ -5,7 +5,8 @@ edition = "2021"
[dependencies]
actix-web = "4"
actix-identity = "0.4"
actix-identity = "0.5"
actix-session = { version = "0.7", features = ["cookie-session"] }
chrono = { version = "0.4", features = ["serde"] }
derive_more = "0.99.5"

View File

@ -1,7 +1,9 @@
use std::future::{ready, Ready};
use actix_identity::Identity;
use actix_web::{dev::Payload, web, Error, FromRequest, HttpRequest, HttpResponse};
use actix_web::{
dev::Payload, web, Error, FromRequest, HttpMessage as _, HttpRequest, HttpResponse,
};
use diesel::prelude::*;
use serde::Deserialize;
@ -27,7 +29,7 @@ impl FromRequest for LoggedUser {
fn from_request(req: &HttpRequest, pl: &mut Payload) -> Self::Future {
if let Ok(identity) = Identity::from_request(req, pl).into_inner() {
if let Some(user_json) = identity.identity() {
if let Ok(user_json) = identity.id() {
if let Ok(user) = serde_json::from_str(&user_json) {
return ready(Ok(user));
}
@ -39,21 +41,21 @@ impl FromRequest for LoggedUser {
}
pub async fn logout(id: Identity) -> HttpResponse {
id.forget();
HttpResponse::Ok().finish()
id.logout();
HttpResponse::NoContent().finish()
}
pub async fn login(
req: HttpRequest,
auth_data: web::Json<AuthData>,
id: Identity,
pool: web::Data<Pool>,
) -> Result<HttpResponse, actix_web::Error> {
let user = web::block(move || query(auth_data.into_inner(), pool)).await??;
let user_string = serde_json::to_string(&user).unwrap();
id.remember(user_string);
Identity::login(&req.extensions(), user_string).unwrap();
Ok(HttpResponse::Ok().finish())
Ok(HttpResponse::NoContent().finish())
}
pub async fn get_me(logged_user: LoggedUser) -> HttpResponse {

View File

@ -1,8 +1,9 @@
#[macro_use]
extern crate diesel;
use actix_identity::{CookieIdentityPolicy, IdentityService};
use actix_web::{middleware, web, App, HttpServer};
use actix_identity::IdentityMiddleware;
use actix_session::{config::PersistentSession, storage::CookieSessionStore, SessionMiddleware};
use actix_web::{cookie::Key, middleware, web, App, HttpServer};
use diesel::{
prelude::*,
r2d2::{self, ConnectionManager},
@ -39,17 +40,21 @@ async fn main() -> std::io::Result<()> {
HttpServer::new(move || {
App::new()
.app_data(web::Data::new(pool.clone()))
.wrap(IdentityMiddleware::default())
.wrap(
SessionMiddleware::builder(
CookieSessionStore::default(),
Key::from(utils::SECRET_KEY.as_bytes()),
)
.session_lifecycle(PersistentSession::default().session_ttl(Duration::days(1)))
.cookie_name("auth-example".to_owned())
.cookie_secure(false)
.cookie_domain(Some(domain.clone()))
.cookie_path("/".to_owned())
.build(),
)
// enable logger
.wrap(middleware::Logger::default())
.wrap(IdentityService::new(
CookieIdentityPolicy::new(utils::SECRET_KEY.as_bytes())
.name("auth")
.path("/")
.domain(domain.as_str())
.max_age(Duration::days(1))
.secure(false), // this can only be true if you have https
))
.app_data(web::JsonConfig::default().limit(4096))
// everything under '/api/' route
.service(
web::scope("/api")

View File

@ -7,7 +7,7 @@ edition = "2021"
actix-files = "0.6"
actix-session = { version = "0.7", features = ["cookie-session"] }
actix-web = "4"
actix-web-lab = "0.17"
actix-web-lab = "0.18"
dotenv = "0.15"
env_logger = "0.9"

View File

@ -10,7 +10,7 @@ env_logger = "0.9"
futures-util = { version = "0.3", default-features = false, features = ["std"] }
log = "0.4"
r2d2 = "0.8"
r2d2_sqlite = "0.20"
rusqlite = "0.27"
r2d2_sqlite = "0.20" # 0.21.0 blocked on sqlx sqlite update
rusqlite = "0.27" # 0.28.0 blocked on sqlx sqlite update
serde = { version = "1", features = ["derive"] }
serde_json = "1"

View File

@ -6,10 +6,10 @@ edition = "2021"
[dependencies]
actix-multipart = "0.4"
actix-web = "4"
actix-web-lab = "0.17"
actix-web-lab = "0.18"
aws-config = "0.46"
aws-sdk-s3 = "0.16"
aws-config = "0.49"
aws-sdk-s3 = "0.19"
dotenv = "0.15"
env_logger = "0.9"

View File

@ -6,7 +6,7 @@ edition = "2021"
[dependencies]
actix = "0.13"
actix-web = "4"
actix-web-lab = "0.17"
actix-web-lab = "0.18"
actix-cors = "0.6"
async-graphql = "4"

View File

@ -5,14 +5,14 @@ edition = "2021"
[dependencies]
actix-web = "4"
actix-web-lab = "0.17"
actix-web-lab = "0.18"
actix-cors = "0.6"
juniper = "0.15"
mysql = "21"
mysql = "22"
r2d2 = "0.8"
r2d2_mysql = "21"
r2d2_mysql = "22"
dotenv = "0.15"
env_logger = "0.9"

View File

@ -5,7 +5,7 @@ edition = "2021"
[dependencies]
actix-web = "4"
actix-web-lab = "0.17"
actix-web-lab = "0.18"
actix-cors = "0.6"
juniper = "0.15"

View File

@ -7,7 +7,7 @@ edition = "2021"
actix-web = { version = "4", features = ["openssl"] }
awc = "3"
clap = { version = "3", features = ["derive"] }
clap = { version = "4", features = ["derive"] }
env_logger = "0.9"
log = "0.4"
url = "2.2"

View File

@ -2,7 +2,7 @@ use std::net::ToSocketAddrs;
use actix_web::{error, middleware, web, App, Error, HttpRequest, HttpResponse, HttpServer};
use awc::Client;
use clap::StructOpt;
use clap::Parser;
use url::Url;
async fn forward(

View File

@ -9,7 +9,7 @@ path = "src/main.rs"
[dependencies]
actix-web = { version = "4", features = ["rustls"] }
actix-web-lab = "0.17"
actix-web-lab = "0.18"
actix-files = "0.6"
env_logger = "0.9"

View File

@ -12,4 +12,4 @@ futures-util = { version = "0.3.17", default-features = false, features = ["std"
log = "0.4"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
validator = { version = "0.15", features = ["derive"] }
validator = { version = "0.16", features = ["derive"] }

View File

@ -5,7 +5,7 @@ edition = "2021"
[dependencies]
actix-web = { version = "4", features = ["rustls"] }
actix-web-lab = "0.17"
actix-web-lab = "0.18"
env_logger = "0.9"
futures-util = { version = "0.3.17", default-features = false, features = ["std"] }

View File

@ -4,10 +4,10 @@ version = "1.0.0"
edition = "2021"
[dependencies]
actix-protobuf = "0.8"
actix-protobuf = "0.9"
actix-web = "4"
env_logger = "0.9"
log = "0.4"
prost = "0.10"
prost-derive = "0.10"
prost = "0.11"
prost-derive = "0.11"

View File

@ -5,7 +5,7 @@ edition = "2021"
[dependencies]
actix-web = "4"
actix-web-lab = "0.16.9"
actix-web-lab = "0.18"
env_logger = "0.9"
futures-util = { version = "0.3.17", default-features = false, features = ["std"] }
log = "0.4"

View File

@ -1,7 +1,7 @@
use std::{sync::Arc, time::Duration};
use actix_web::rt::time::interval;
use actix_web_lab::sse::{sse, Sse, SseData, SseMessage, SseSender};
use actix_web_lab::sse::{self, ChannelStream, Sse};
use futures_util::future;
use parking_lot::Mutex;
@ -11,7 +11,7 @@ pub struct Broadcaster {
#[derive(Debug, Clone, Default)]
struct BroadcasterInner {
clients: Vec<SseSender>,
clients: Vec<sse::Sender>,
}
impl Broadcaster {
@ -47,7 +47,7 @@ impl Broadcaster {
for client in clients {
if client
.send(SseMessage::Comment("ping".into()))
.send(sse::Event::Comment("ping".into()))
.await
.is_ok()
{
@ -59,10 +59,10 @@ impl Broadcaster {
}
/// Registers client with broadcaster, returning an SSE response body.
pub async fn new_client(&self) -> Sse {
let (tx, rx) = sse(10);
pub async fn new_client(&self) -> Sse<ChannelStream> {
let (tx, rx) = sse::channel(10);
tx.send(SseData::new("connected")).await.unwrap();
tx.send(sse::Data::new("connected")).await.unwrap();
self.inner.lock().clients.push(tx);
@ -73,7 +73,9 @@ impl Broadcaster {
pub async fn broadcast(&self, msg: &str) {
let clients = self.inner.lock().clients.clone();
let send_futures = clients.iter().map(|client| client.send(SseData::new(msg)));
let send_futures = clients
.iter()
.map(|client| client.send(sse::Data::new(msg)));
// try to send to all clients, ignoring failures
// disconnected clients will get swept up by `remove_stale_clients`

View File

@ -6,7 +6,7 @@ description = "Send a request to the server to shut it down"
[dependencies]
actix-web = "4"
actix-web-lab = "0.17"
actix-web-lab = "0.18"
env_logger = "0.9"
log = "0.4"

View File

@ -5,7 +5,7 @@ edition = "2021"
[dependencies]
actix-web = "4"
actix-web-lab = "0.17"
actix-web-lab = "0.18"
fluent-templates = { version = "0.8", features = ["handlebars"] }
handlebars = { version = "4.3", features = ["dir_source"] }
serde = { version = "1", features = ["derive"] }

View File

@ -10,5 +10,5 @@ actix-utils = "3"
env_logger = "0.9"
log = "0.4"
minijinja = { version = "0.23", features = ["source"] }
minijinja-autoreload = "0.23"
minijinja = { version = "0.24", features = ["source"] }
minijinja-autoreload = "0.24"

View File

@ -5,8 +5,8 @@ edition = "2021"
[dependencies]
actix-web = "4"
actix-web-lab = "0.17"
actix-web-lab = "0.18"
env_logger = "0.9"
log = "0.4"
sailfish = "0.4"
sailfish = "0.5"