Skip to content

Commit

Permalink
Update (and fix) templates and examples. (LukeMathWalker#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeMathWalker authored Mar 23, 2024
1 parent dbe9683 commit af78d02
Show file tree
Hide file tree
Showing 18 changed files with 961 additions and 1,163 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions examples/realworld/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions examples/realworld/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ name = "bp"

[dependencies]
anyhow = "1"
pavex_cli_client = { path = "../../../libs/pavex_cli_client" }
pavex_cli_client = "0.1"
cargo_px_env = "0.1"
pavex = { path = "../../../libs/pavex" }
pavex_tracing = { path = "../../../libs/pavex_tracing" }
pavex = "0.1"
pavex_tracing = "0.1"

time = { version = "0.3", features = ["serde"] }
sqlx = { version = "0.7", features = [ "runtime-tokio", "tls-rustls", "migrate", "uuid", "macros", "time", "postgres" ] }
Expand Down
10 changes: 2 additions & 8 deletions examples/realworld/app/src/telemetry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use pavex::blueprint::{constructor::CloningStrategy, Blueprint};
use pavex::f;
use pavex::middleware::Next;
use pavex::request::path::MatchedPathPattern;
use pavex::request::RequestHead;
use pavex::response::Response;
Expand All @@ -13,15 +12,14 @@ use pavex_tracing::fields::{
URL_PATH, URL_QUERY, USER_AGENT_ORIGINAL,
};
use pavex_tracing::RootSpan;
use std::future::IntoFuture;

/// Register telemetry middlewares, an error observer and the relevant constructors
/// with the application blueprint.
pub(crate) fn register(bp: &mut Blueprint) {
bp.request_scoped(f!(self::root_span))
.cloning(CloningStrategy::CloneIfNecessary);
bp.wrap(f!(pavex_tracing::logger));
bp.wrap(f!(self::response_logger));
bp.post_process(f!(self::response_logger));
bp.error_observer(f!(self::error_logger));
}

Expand Down Expand Up @@ -59,11 +57,7 @@ pub fn root_span(

/// A middleware to enrich [`RootSpan`] with information extracted from the
/// outgoing response.
pub async fn response_logger<T>(next: Next<T>, root_span: &RootSpan) -> Response
where
T: IntoFuture<Output = Response>,
{
let response = next.await;
pub async fn response_logger(response: Response, root_span: &RootSpan) -> Response {
root_span.record(
HTTP_RESPONSE_STATUS_CODE,
http_response_status_code(&response),
Expand Down
2 changes: 1 addition & 1 deletion examples/realworld/scripts/init_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ done

export DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}
sqlx database create
sqlx migrate run --source conduit_core/migrations
sqlx migrate run --source app/migrations

>&2 echo "Postgres has been migrated, ready to go!"
4 changes: 2 additions & 2 deletions examples/realworld/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ name = "api"
tokio = { version = "1", features = ["full"] }
anyhow = "1"
server_sdk = { path = "../server_sdk" }
pavex = { path = "../../../libs/pavex" }
pavex = "0.1"
app = { path = "../app" }

# Configuration
Expand All @@ -22,7 +22,7 @@ serde = { version = "1", features = ["derive"]}
tracing = "0.1"
tracing-subscriber = { version = "0.3", default-features = false, features = ["env-filter", "smallvec", "std", "registry", "tracing-log"] }
tracing-bunyan-formatter = "0.3"
pavex_tracing = { path = "../../../libs/pavex_tracing" }
pavex_tracing = "0.1"

[dev-dependencies]
reqwest = { version = "0.11", features = ["json"] }
Expand Down
8 changes: 4 additions & 4 deletions examples/realworld/server/tests/integration/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use api_server::configuration::{ApplicationProfile, Config};
use api_server_sdk::{build_application_state, run};
use pavex::server::Server;
use server::configuration::{ApplicationProfile, Config};
use server_sdk::{build_application_state, run};
use std::sync::Once;
use tracing::subscriber::set_global_default;
use tracing_subscriber::EnvFilter;
Expand Down Expand Up @@ -38,8 +38,8 @@ impl TestApi {
}

fn get_config() -> Config {
let mut config = Config::load(Some(ApplicationProfile::Test))
.expect("Failed to load test configuration");
let mut config =
Config::load(Some(ApplicationProfile::Dev)).expect("Failed to load test configuration");

// We generate the key pair on the fly rather than hardcoding it in the
// configuration file.
Expand Down
4 changes: 2 additions & 2 deletions examples/realworld/server_sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ app = { version = "0.1.0", path = "../app", package = "app" }
http = { version = "1.0.0", package = "http" }
hyper = { version = "1.2.0", package = "hyper" }
jsonwebtoken = { version = "8.3.0", package = "jsonwebtoken" }
pavex = { version = "0.1.18", path = "../../../libs/pavex", package = "pavex" }
pavex = { version = "0.1.21", path = "../../../libs/pavex", package = "pavex" }
pavex_matchit = { version = "0.7.4", package = "pavex_matchit" }
pavex_tracing = { version = "0.1.18", path = "../../../libs/pavex_tracing", package = "pavex_tracing" }
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" }
Loading

0 comments on commit af78d02

Please sign in to comment.