cargo fmt
This commit is contained in:
parent
5dd01a5d4c
commit
20f4ae0658
|
@ -2,7 +2,7 @@ use axum::{
|
||||||
body,
|
body,
|
||||||
extract::State,
|
extract::State,
|
||||||
middleware::Next,
|
middleware::Next,
|
||||||
response::{Html, IntoResponse, Response, Redirect},
|
response::{Html, IntoResponse, Response},
|
||||||
routing::get,
|
routing::get,
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
|
@ -10,7 +10,7 @@ use hyper::{header::CONTENT_TYPE, Request, StatusCode};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use prometheus::{opts, Encoder, IntCounterVec, TextEncoder};
|
use prometheus::{opts, Encoder, IntCounterVec, TextEncoder};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tracing::{info_span, instrument, log::*, Instrument};
|
use tracing::{instrument, log::*};
|
||||||
|
|
||||||
use crate::{AppState, WebsiteError};
|
use crate::{AppState, WebsiteError};
|
||||||
|
|
||||||
|
@ -37,7 +37,10 @@ pub fn routes(state: &Arc<AppState>) -> Router<Arc<AppState>> {
|
||||||
.layer(axum::middleware::from_fn(metrics_middleware))
|
.layer(axum::middleware::from_fn(metrics_middleware))
|
||||||
.route("/healthcheck", get(healthcheck))
|
.route("/healthcheck", get(healthcheck))
|
||||||
.route("/metrics", get(metrics))
|
.route("/metrics", get(metrics))
|
||||||
.route_service("/posts/:slug/*path", tower_http::services::ServeDir::new("./"))
|
.route_service(
|
||||||
|
"/posts/:slug/*path",
|
||||||
|
tower_http::services::ServeDir::new("./"),
|
||||||
|
)
|
||||||
.route_service("/static/*path", tower_http::services::ServeDir::new("./"))
|
.route_service("/static/*path", tower_http::services::ServeDir::new("./"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::{Path, State},
|
extract::{Path, State},
|
||||||
response::{Html, Redirect, IntoResponse},
|
response::{Html, Redirect},
|
||||||
routing::get,
|
routing::get,
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
|
@ -87,8 +87,7 @@ pub async fn redirect(
|
||||||
) -> Result<Redirect, WebsiteError> {
|
) -> Result<Redirect, WebsiteError> {
|
||||||
if state.posts.contains_key(&slug) {
|
if state.posts.contains_key(&slug) {
|
||||||
Ok(Redirect::permanent(&format!("/posts/{slug}/")))
|
Ok(Redirect::permanent(&format!("/posts/{slug}/")))
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Err(WebsiteError::NotFound)
|
Err(WebsiteError::NotFound)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,8 +72,7 @@ pub async fn redirect(
|
||||||
) -> Result<Redirect, WebsiteError> {
|
) -> Result<Redirect, WebsiteError> {
|
||||||
if state.tags.contains_key(&slug) {
|
if state.tags.contains_key(&slug) {
|
||||||
Ok(Redirect::permanent(&format!("/tags/{slug}/")))
|
Ok(Redirect::permanent(&format!("/tags/{slug}/")))
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Err(WebsiteError::NotFound)
|
Err(WebsiteError::NotFound)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -37,9 +37,11 @@ async fn main() -> Result<()> {
|
||||||
let app = handlers::routes(&state)
|
let app = handlers::routes(&state)
|
||||||
.layer(CorsLayer::permissive())
|
.layer(CorsLayer::permissive())
|
||||||
.layer(CompressionLayer::new())
|
.layer(CompressionLayer::new())
|
||||||
.layer(tower_http::trace::TraceLayer::new_for_http()
|
.layer(
|
||||||
|
tower_http::trace::TraceLayer::new_for_http()
|
||||||
.make_span_with(make_span)
|
.make_span_with(make_span)
|
||||||
.on_response(on_response))
|
.on_response(on_response),
|
||||||
|
)
|
||||||
.with_state(state);
|
.with_state(state);
|
||||||
|
|
||||||
info!("Now listening at http://localhost:8180");
|
info!("Now listening at http://localhost:8180");
|
||||||
|
@ -71,10 +73,7 @@ fn make_span(request: &Request<Body>) -> Span {
|
||||||
.map(|mp| mp.as_str())
|
.map(|mp| mp.as_str())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let method = request.method().as_str();
|
let method = request.method().as_str();
|
||||||
let target = uri
|
let target = uri.path_and_query().map(|p| p.as_str()).unwrap_or_default();
|
||||||
.path_and_query()
|
|
||||||
.map(|p| p.as_str())
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
let name = format!("{method} {route}");
|
let name = format!("{method} {route}");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue