Apply formatting and satisfy lints
This commit is contained in:
parent
4db4c703d1
commit
82f1f0c63c
5 changed files with 35 additions and 18 deletions
|
|
@ -5,4 +5,3 @@ pub fn log<F>(function: &F, message: &str) {
|
||||||
std::any::type_name_of_val(function).replace("en::", ""),
|
std::any::type_name_of_val(function).replace("en::", ""),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ use axum::{
|
||||||
use crate::formats::{Format, populate_graph, serialize_graph};
|
use crate::formats::{Format, populate_graph, serialize_graph};
|
||||||
use crate::handlers;
|
use crate::handlers;
|
||||||
|
|
||||||
#[expect(clippy::unused_async)]
|
|
||||||
pub async fn file(file_path: &str, content_type: &str) -> Response<Body> {
|
pub async fn file(file_path: &str, content_type: &str) -> Response<Body> {
|
||||||
let content = match std::fs::read(file_path) {
|
let content = match std::fs::read(file_path) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
|
|
@ -23,15 +22,19 @@ pub async fn file(file_path: &str, content_type: &str) -> Response<Body> {
|
||||||
if let Some(h) = response.headers_mut().insert(header, header_value) {
|
if let Some(h) = response.headers_mut().insert(header, header_value) {
|
||||||
crate::dev::log(
|
crate::dev::log(
|
||||||
&file,
|
&file,
|
||||||
&format!("Overwrote existing header {h:?} because a header for \
|
&format!(
|
||||||
the same key existed")
|
"Overwrote existing header {h:?} because a header for \
|
||||||
|
the same key existed"
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
crate::dev::log(
|
crate::dev::log(
|
||||||
&file,
|
&file,
|
||||||
&format!("[file_handler] Failed to create content type \
|
&format!(
|
||||||
header value from {content_type}")
|
"Failed to create content type \
|
||||||
|
header value from {content_type}"
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,15 +20,17 @@ pub fn make_response(
|
||||||
{
|
{
|
||||||
crate::dev::log(
|
crate::dev::log(
|
||||||
&make_response,
|
&make_response,
|
||||||
&format!("Overwrote header {overwritten:?} \
|
&format!(
|
||||||
|
"Overwrote header {overwritten:?} \
|
||||||
because another for key {} already existed",
|
because another for key {} already existed",
|
||||||
header.0)
|
header.0
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
crate::dev::log(
|
crate::dev::log(
|
||||||
&make_response,
|
&make_response,
|
||||||
&format!("Failed to wrap header value {}", header.1)
|
&format!("Failed to wrap header value {}", header.1),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ pub(super) fn by_filename(
|
||||||
make_response(&body, status_code, &[(header::CONTENT_TYPE, "text/html")])
|
make_response(&body, status_code, &[(header::CONTENT_TYPE, "text/html")])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[expect(clippy::unused_async)]
|
||||||
pub async fn fixed(name: &str) -> Response<Body> {
|
pub async fn fixed(name: &str) -> Response<Body> {
|
||||||
by_filename(name, &tera::Context::new(), 500, None, false)
|
by_filename(name, &tera::Context::new(), 500, None, false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
30
src/main.rs
30
src/main.rs
|
|
@ -28,24 +28,36 @@ async fn main() {
|
||||||
if trace.status() == std::backtrace::BacktraceStatus::Captured {
|
if trace.status() == std::backtrace::BacktraceStatus::Captured {
|
||||||
eprintln!("\n Stack trace:\n{trace:#?}");
|
eprintln!("\n Stack trace:\n{trace:#?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/", get(|| handlers::navigation::nexus("index.html"))
|
.route(
|
||||||
.post(handlers::navigation::search))
|
"/",
|
||||||
.route("/graph/toml", get(|| handlers::fixed::serial(&Format::Toml)))
|
get(|| handlers::navigation::nexus("index.html"))
|
||||||
.route("/graph/json", get(|| handlers::fixed::serial(&Format::Json)))
|
.post(handlers::navigation::search),
|
||||||
|
)
|
||||||
|
.route(
|
||||||
|
"/graph/toml",
|
||||||
|
get(|| handlers::fixed::serial(&Format::Toml)),
|
||||||
|
)
|
||||||
|
.route(
|
||||||
|
"/graph/json",
|
||||||
|
get(|| handlers::fixed::serial(&Format::Json)),
|
||||||
|
)
|
||||||
.route(
|
.route(
|
||||||
"/static/style.css",
|
"/static/style.css",
|
||||||
get(|| handlers::fixed::file("./static/style.css", "text/css")),
|
get(|| handlers::fixed::file("./static/style.css", "text/css")),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/static/favicon.svg",
|
"/static/favicon.svg",
|
||||||
get(|| handlers::fixed::file("./static/favicon.svg", "image/svg+xml")),
|
get(|| {
|
||||||
|
handlers::fixed::file("./static/favicon.svg", "image/svg+xml")
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.route(
|
||||||
|
"/node/{node_id}",
|
||||||
|
get(handlers::graph::node).post(handlers::graph::node),
|
||||||
)
|
)
|
||||||
.route("/node/{node_id}", get(handlers::graph::node)
|
|
||||||
.post(handlers::graph::node))
|
|
||||||
.route("/tree", get(|| handlers::navigation::nexus("tree.html")))
|
.route("/tree", get(|| handlers::navigation::nexus("tree.html")))
|
||||||
.route("/about", get(|| handlers::template::fixed("about.html")))
|
.route("/about", get(|| handlers::template::fixed("about.html")))
|
||||||
.route(
|
.route(
|
||||||
|
|
@ -65,7 +77,7 @@ async fn main() {
|
||||||
&main,
|
&main,
|
||||||
&format!(
|
&format!(
|
||||||
"Failed to serve application with axum::serve: {e:#?}"
|
"Failed to serve application with axum::serve: {e:#?}"
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue