From 6613f337ce1969d08abafbbd02c99ec439d27486 Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 13 Apr 2024 22:31:46 +0200 Subject: [PATCH] feat: cors and tracing layers --- Cargo.toml | 1 + src/main.rs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 3f08b715..3bde751c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,6 +40,7 @@ sea-orm-migration = { version = "0.12", optional = true } # mastodon mastodon-async-entities = { version = "1.1.0", optional = true } time = { version = "0.3", features = ["serde"], optional = true } +tower-http = { version = "0.5.2", features = ["cors", "trace"] } [features] default = ["faker", "migrations", "mastodon"] diff --git a/src/main.rs b/src/main.rs index 95aa4e84..4204594d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,6 +14,7 @@ use clap::{Parser, Subcommand}; use sea_orm::{ConnectOptions, Database, EntityTrait, IntoActiveModel}; pub use errors::UpubResult as Result; +use tower_http::{cors::CorsLayer, trace::TraceLayer}; use crate::server::fetcher::Fetchable; @@ -107,6 +108,8 @@ async fn main() { let router = axum::Router::new() .ap_routes() .mastodon_routes() // no-op if mastodon feature is disabled + .layer(CorsLayer::permissive()) + .layer(TraceLayer::new_for_http()) .with_state(ctx); // run our app with hyper, listening locally on port 3000