Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion crates/http-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ axum = "0.6.18"
color-eyre = "0.6.2"
clap = { version = "4.2.7", features = ["derive"] }
tokio = { version = "1.28.1", features = ["macros", "rt-multi-thread"] }

tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
[profile.release]
debug = 1

Expand Down
15 changes: 10 additions & 5 deletions crates/http-server/src/server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use axum::Router;

use crate::cli::Cli;
use axum::{routing::get, Router};
use tracing::{info, Level};
use tracing_subscriber::EnvFilter;

pub struct Server(Router);
pub struct Server(pub Router);
Comment on lines -5 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets keep the Router encapsulated and use the getter we have as a method instead


impl Server {
pub fn router(self) -> Router {
Expand All @@ -12,12 +13,16 @@ impl Server {

impl From<Cli> for Server {
fn from(value: Cli) -> Self {
let filter = EnvFilter::from_default_env().add_directive(Level::INFO.into());

tracing_subscriber::fmt().with_env_filter(filter).init();
Comment on lines 15 to +18
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking advantage of the Cli I think we could have a log argument we could use to pass it to the tracing_subscriber. This way we could do:

http-server --log debug

This would set the Level::DEBUG in L16.


let mut app = Router::new();

if value.port == 7878 {
app = app.route("/", axum::routing::get(|| async { "Hello, Rust!" }));
app = app.route("/", get(|| async { info!("Hello, Rust!") }));
} else {
app = app.route("/", axum::routing::get(|| async { "Hello, World!" }));
app = app.route("/", get(|| async { info!("Hello, World!") }));
}

Self(app)
Expand Down