feat: cors and tracing layers

This commit is contained in:
əlemi 2024-04-13 22:31:46 +02:00
parent 85375ba1fb
commit 6613f337ce
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 4 additions and 0 deletions

View file

@ -40,6 +40,7 @@ sea-orm-migration = { version = "0.12", optional = true }
# mastodon # mastodon
mastodon-async-entities = { version = "1.1.0", optional = true } mastodon-async-entities = { version = "1.1.0", optional = true }
time = { version = "0.3", features = ["serde"], optional = true } time = { version = "0.3", features = ["serde"], optional = true }
tower-http = { version = "0.5.2", features = ["cors", "trace"] }
[features] [features]
default = ["faker", "migrations", "mastodon"] default = ["faker", "migrations", "mastodon"]

View file

@ -14,6 +14,7 @@ use clap::{Parser, Subcommand};
use sea_orm::{ConnectOptions, Database, EntityTrait, IntoActiveModel}; use sea_orm::{ConnectOptions, Database, EntityTrait, IntoActiveModel};
pub use errors::UpubResult as Result; pub use errors::UpubResult as Result;
use tower_http::{cors::CorsLayer, trace::TraceLayer};
use crate::server::fetcher::Fetchable; use crate::server::fetcher::Fetchable;
@ -107,6 +108,8 @@ async fn main() {
let router = axum::Router::new() let router = axum::Router::new()
.ap_routes() .ap_routes()
.mastodon_routes() // no-op if mastodon feature is disabled .mastodon_routes() // no-op if mastodon feature is disabled
.layer(CorsLayer::permissive())
.layer(TraceLayer::new_for_http())
.with_state(ctx); .with_state(ctx);
// run our app with hyper, listening locally on port 3000 // run our app with hyper, listening locally on port 3000