1
0
Fork 0

cargo fmt

This commit is contained in:
Adrian Hedqvist 2023-04-02 15:27:06 +02:00
parent 5dd01a5d4c
commit 20f4ae0658
4 changed files with 15 additions and 15 deletions

View file

@ -2,7 +2,7 @@ use axum::{
body,
extract::State,
middleware::Next,
response::{Html, IntoResponse, Response, Redirect},
response::{Html, IntoResponse, Response},
routing::get,
Router,
};
@ -10,7 +10,7 @@ use hyper::{header::CONTENT_TYPE, Request, StatusCode};
use lazy_static::lazy_static;
use prometheus::{opts, Encoder, IntCounterVec, TextEncoder};
use std::sync::Arc;
use tracing::{info_span, instrument, log::*, Instrument};
use tracing::{instrument, log::*};
use crate::{AppState, WebsiteError};
@ -37,7 +37,10 @@ pub fn routes(state: &Arc<AppState>) -> Router<Arc<AppState>> {
.layer(axum::middleware::from_fn(metrics_middleware))
.route("/healthcheck", get(healthcheck))
.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("./"))
}

View file

@ -2,7 +2,7 @@ use std::sync::Arc;
use axum::{
extract::{Path, State},
response::{Html, Redirect, IntoResponse},
response::{Html, Redirect},
routing::get,
Router,
};
@ -87,8 +87,7 @@ pub async fn redirect(
) -> Result<Redirect, WebsiteError> {
if state.posts.contains_key(&slug) {
Ok(Redirect::permanent(&format!("/posts/{slug}/")))
}
else {
} else {
Err(WebsiteError::NotFound)
}
}

View file

@ -72,8 +72,7 @@ pub async fn redirect(
) -> Result<Redirect, WebsiteError> {
if state.tags.contains_key(&slug) {
Ok(Redirect::permanent(&format!("/tags/{slug}/")))
}
else {
} else {
Err(WebsiteError::NotFound)
}
}

View file

@ -37,9 +37,11 @@ async fn main() -> Result<()> {
let app = handlers::routes(&state)
.layer(CorsLayer::permissive())
.layer(CompressionLayer::new())
.layer(tower_http::trace::TraceLayer::new_for_http()
.make_span_with(make_span)
.on_response(on_response))
.layer(
tower_http::trace::TraceLayer::new_for_http()
.make_span_with(make_span)
.on_response(on_response),
)
.with_state(state);
info!("Now listening at http://localhost:8180");
@ -71,10 +73,7 @@ fn make_span(request: &Request<Body>) -> Span {
.map(|mp| mp.as_str())
.unwrap_or_default();
let method = request.method().as_str();
let target = uri
.path_and_query()
.map(|p| p.as_str())
.unwrap_or_default();
let target = uri.path_and_query().map(|p| p.as_str()).unwrap_or_default();
let name = format!("{method} {route}");