Skip to content

Commit

Permalink
Cookies integration (LukeMathWalker#234)
Browse files Browse the repository at this point in the history
We re-export `biscotti` as our cookie API, with one key difference: we
don't re-export `ResponseCookies` as is.
We instead expose our own `ResponseCookies` type that wraps around
`biscotti`'s one, constraining its generic lifetime to be `'static`
since that's what the vast majority of applications will need.

The integration is not yet ready for prime time—we need a section in the
guide. But that'll come in a follow-up PR.

Other changes:

- Pavex gained a top-level `error` module, where I added an
`UnexpectedError` type. Almost any application defines one as a
"catch-all" error variant, therefore it looked like a win to make it
first-party since we need it anyway for our own error enums.
  • Loading branch information
LukeMathWalker authored Apr 2, 2024
1 parent 5b1eee7 commit 397dc04
Show file tree
Hide file tree
Showing 17 changed files with 3,654 additions and 1,023 deletions.
740 changes: 420 additions & 320 deletions examples/realworld/Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions examples/realworld/app/src/blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::routes::profiles::profiles_bp;
use crate::routes::users::users_bp;
use crate::telemetry;
use pavex::blueprint::{router::GET, Blueprint};
use pavex::cookie::CookieKit;
use pavex::f;
use pavex::kit::ApiKit;

Expand All @@ -14,6 +15,7 @@ pub fn blueprint() -> Blueprint {
ApiKit::new().register(&mut bp);
telemetry::register(&mut bp);
ApplicationConfig::register(&mut bp);
CookieKit::new().register(&mut bp);

bp.nest_at("/articles", articles_bp());
bp.nest_at("/profiles", profiles_bp());
Expand Down
7 changes: 7 additions & 0 deletions examples/realworld/app/src/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use jsonwebtoken::{DecodingKey, EncodingKey};
use pavex::blueprint::Blueprint;
use pavex::cookie::ProcessorConfig;
use pavex::f;
use secrecy::{ExposeSecret, Secret};
use serde_aux::field_attributes::deserialize_number_from_string;
Expand All @@ -11,6 +12,7 @@ use sqlx::postgres::{PgConnectOptions, PgSslMode};
pub struct ApplicationConfig {
pub database: DatabaseConfig,
pub auth: AuthConfig,
pub cookie: ProcessorConfig,
}

impl ApplicationConfig {
Expand All @@ -22,9 +24,14 @@ impl ApplicationConfig {
&self.auth
}

pub fn cookie_config(&self) -> ProcessorConfig {
self.cookie.clone()
}

pub fn register(bp: &mut Blueprint) {
bp.singleton(f!(self::ApplicationConfig::database_config));
bp.singleton(f!(self::ApplicationConfig::auth_config));
bp.singleton(f!(self::ApplicationConfig::cookie_config));
bp.singleton(f!(self::DatabaseConfig::get_pool));
bp.singleton(f!(self::AuthConfig::decoding_key));
}
Expand Down
4 changes: 2 additions & 2 deletions examples/realworld/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ app = { path = "../app" }

# Configuration
figment = { version = "0.10", features = ["env", "yaml"] }
serde = { version = "1", features = ["derive"]}
serde = { version = "1", features = ["derive"] }

# Telemetry
tracing = "0.1"
Expand All @@ -25,7 +25,7 @@ tracing-bunyan-formatter = "0.3"
pavex_tracing = "0.1"

[dev-dependencies]
reqwest = { version = "0.11", features = ["json"] }
reqwest = { version = "0.12", features = ["json"] }
jwt-simple = "0.11"
secrecy = "0.8"
serde_json = "1"
13 changes: 7 additions & 6 deletions examples/realworld/server_sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ verifier_args = ["--check"]

[dependencies]
app = { version = "0.1.0", path = "../app", package = "app" }
http = { version = "1.0.0", package = "http" }
biscotti = { version = "0.3.2", package = "biscotti" }
http = { version = "1.1.0", package = "http" }
hyper = { version = "1.2.0", package = "hyper" }
jsonwebtoken = { version = "8.3.0", package = "jsonwebtoken" }
pavex = { version = "0.1.21", path = "../../../libs/pavex", package = "pavex" }
pavex = { version = "0.1.23", path = "../../../libs/pavex", package = "pavex" }
pavex_matchit = { version = "0.7.4", package = "pavex_matchit" }
pavex_tracing = { version = "0.1.21", path = "../../../libs/pavex_tracing", package = "pavex_tracing" }
sqlx_core = { version = "0.7.3", package = "sqlx-core" }
sqlx_postgres = { version = "0.7.3", package = "sqlx-postgres" }
thiserror = { version = "1.0.57", package = "thiserror" }
pavex_tracing = { version = "0.1.23", path = "../../../libs/pavex_tracing", package = "pavex_tracing" }
sqlx_core = { version = "0.7.4", package = "sqlx-core" }
sqlx_postgres = { version = "0.7.4", package = "sqlx-postgres" }
thiserror = { version = "1.0.58", package = "thiserror" }
Loading

0 comments on commit 397dc04

Please sign in to comment.