diff --git a/Cargo.toml b/Cargo.toml index 2df5dc5..ec9225b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,4 +12,4 @@ tokio = { version = "1.53.1", features = ["rt", "rt-multi-thread", "macros", "sy ed25519-dalek = { version = "2", features = ["rand_core"] } rand = "0.8" bs58 = "0.5.1" -tower-http = { version = "0.7.0", features = ["fs"] } +tower-http = { version = "0.7.0", features = ["fs", "cors"] } diff --git a/src/main.rs b/src/main.rs index 467870b..8897bfd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,10 @@ use axum::{ response::Response, routing::{any, get}, }; -use tower_http::services::ServeFile; +use tower_http::{ + cors::{Any, CorsLayer}, + services::ServeFile, +}; use crate::server::Server; @@ -22,11 +25,17 @@ use crate::server::Server; async fn main() -> anyhow::Result<()> { let server = Server::new().await?; + let cors = CorsLayer::new() + .allow_origin(Any) + .allow_methods(Any) + .allow_headers(Any); + let app = Router::new() .route("/meta", get(meta)) .route("/", any(ws_handler)) .route_service("/icon", ServeFile::new("./icon.png")) - .with_state(server.clone()); + .with_state(server.clone()) + .layer(cors); let listener = tokio::net::TcpListener::bind(SocketAddr::new( IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)),