Skip to content

Commit

Permalink
feat: migrate to axum router
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed May 27, 2024
1 parent d4d0db2 commit 3dfb480
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 200 deletions.
25 changes: 18 additions & 7 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ parking_lot = "0.12"
pulldown-cmark = "0.11"
relative-path = { version = "1", features = ["serde"] }
reqwest = { version = "0.12", features = ["json"] }
route-recognizer = "0.3"
rustsec = "0.29"
semver = { version = "1.0", features = ["serde"] }
serde = { version = "1", features = ["derive"] }
serde_urlencoded = "0.7"
tokio = { version = "1.24.2", features = ["rt-multi-thread", "macros", "sync", "time"] }
toml = "0.8"
tower = "0.4"
tower-http = { version = "0.5", features = ["normalize-path", "trace"] }
tracing = "0.1.30"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

Expand Down
17 changes: 3 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ use std::{
time::Duration,
};

use axum::{extract::Request, Router};
use cadence::{QueuingMetricSink, UdpMetricSink};
use reqwest::redirect::Policy as RedirectPolicy;
use tracing::Instrument as _;
use tokio::net::TcpListener;

mod engine;
mod interactors;
Expand Down Expand Up @@ -90,18 +89,8 @@ async fn main() {

let app = App::new(engine.clone());

let lst = tokio::net::TcpListener::bind(addr).await.unwrap();

let router = Router::new().fallback(|req: Request| async move {
let path = req.uri().path().to_owned();

app.handle(req)
.instrument(tracing::info_span!("@", %path))
.await
.unwrap()
});

let server = axum::serve(lst, router);
let lst = TcpListener::bind(addr).await.unwrap();
let server = axum::serve(lst, App::router().with_state(app));

tracing::info!("Server running on port {port}");

Expand Down
2 changes: 2 additions & 0 deletions src/server/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub const STATIC_STYLE_CSS_ETAG: &str = concat!(
include_str!(concat!(env!("OUT_DIR"), "/style.css.sha1")),
"\""
);

pub const STATIC_FAVICON_PATH: &str = "/static/logo.svg";
pub static STATIC_FAVICON: &[u8] = include_bytes!("../../assets/logo.svg");

pub static STATIC_LINKS_JS: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/links.js"));
Expand Down
Loading

0 comments on commit 3dfb480

Please sign in to comment.