Skip to content

Commit

Permalink
feat: add logging middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
migueloller committed Oct 13, 2023
1 parent 6b2de61 commit 58fd6b7
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
60 changes: 59 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ name = "zero2prod"
actix-web = "4"
chrono = { version = "0.4.22", default-features = false, features = ["clock"] }
config = "0.13"
env_logger = "0.9"
serde = { version = "1", features = ["derive"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
uuid = { version = "1", features = ["v4"] }
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use env_logger::Env;
use sqlx::PgPool;
use std::net::TcpListener;
use zero2prod::{configuration::get_configuration, startup::run};

#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();

let configuration = get_configuration().expect("Failed to read configuration.");
let connection_pool = PgPool::connect(&configuration.database.connection_string())
.await
Expand Down
3 changes: 2 additions & 1 deletion src/startup.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use crate::routes::{health_check, subscribe};
use actix_web::{dev::Server, web, App, HttpServer};
use actix_web::{dev::Server, middleware::Logger, web, App, HttpServer};
use sqlx::PgPool;
use std::net::TcpListener;

pub fn run(listener: TcpListener, db_pool: PgPool) -> Result<Server, std::io::Error> {
let db_pool = web::Data::new(db_pool);
let server = HttpServer::new(move || {
App::new()
.wrap(Logger::default())
.route("/health_check", web::get().to(health_check))
.route("/subscriptions", web::post().to(subscribe))
.app_data(db_pool.clone())
Expand Down

0 comments on commit 58fd6b7

Please sign in to comment.