diff --git a/Cargo.lock b/Cargo.lock index 63f8673..cb9c29a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,6 +19,21 @@ dependencies = [ "tracing", ] +[[package]] +name = "actix-cors" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b340e9cfa5b08690aae90fb61beb44e9b06f44fe3d0f93781aaa58cfba86245e" +dependencies = [ + "actix-utils", + "actix-web", + "derive_more", + "futures-util", + "log", + "once_cell", + "smallvec", +] + [[package]] name = "actix-http" version = "3.3.1" @@ -893,6 +908,7 @@ dependencies = [ name = "images" version = "0.1.0" dependencies = [ + "actix-cors", "actix-web", "clap", "lazy_static", @@ -1694,6 +1710,7 @@ dependencies = [ name = "tatoeba" version = "0.1.0" dependencies = [ + "actix-cors", "actix-web", "clap", "derive_more", diff --git a/flake.nix b/flake.nix index d5ad55c..1767925 100644 --- a/flake.nix +++ b/flake.nix @@ -40,7 +40,7 @@ pname = "tatoeba"; version = "0.1.0"; buildAndTestSubdir = "tatoeba"; - cargoHash = "sha256-AK47aWFl4eLIVHy27iE2MX62+dfjidlMZT1/uzxQh4E="; + cargoHash = "sha256-/mtl2kes7KmT3Vq+M/kpezhRTKLju3ZRXHFf2Zblczo="; meta = meta // { description = "A proxy of the Tatoeba API with no CORS restrictions."; }; @@ -49,7 +49,7 @@ pname = "images"; version = "0.1.0"; buildAndTestSubdir = "images"; - cargoHash = "sha256-t7IDZJcpYc6eftNedFCRlJ+LQ1O2L2c/XjX8+YqZcjI="; + cargoHash = "sha256-sxge+4WuT8iEVihiqvUAdS+n6U+NzEhfJ0p7lc+uLHE="; meta = meta // { description = "An API for fetching images of a query, sourced from Microsoft Bing."; }; diff --git a/images/Cargo.toml b/images/Cargo.toml index bb707c3..e3d8be0 100644 --- a/images/Cargo.toml +++ b/images/Cargo.toml @@ -19,3 +19,4 @@ lazy_static = "1.4.0" rand = "0.8.5" serde_json = "1.0.104" clap = { version = "4.3.21", features = ["derive"] } +actix-cors = "0.6.4" diff --git a/images/src/main.rs b/images/src/main.rs index 00d18c7..679ca14 100644 --- a/images/src/main.rs +++ b/images/src/main.rs @@ -1,3 +1,4 @@ +use actix_cors::Cors; use utils::error::Result; use actix_web::{get, http::header, web, App, HttpResponse, HttpServer, Responder}; @@ -72,13 +73,14 @@ async fn route_query_index(path: web::Path<(String, usize)>) -> Result std::io::Result<()> { - HttpServer::new(|| { + HttpServer::new(|| App::new() .service(route_query_list) .service(route_query) .service(route_query_random) .service(route_query_index) - }) + .wrap(Cors::permissive()) + ) .bind(("127.0.0.1", Args::parse().port))? .run() .await diff --git a/tatoeba/Cargo.toml b/tatoeba/Cargo.toml index fc722bf..5b60da7 100644 --- a/tatoeba/Cargo.toml +++ b/tatoeba/Cargo.toml @@ -16,3 +16,4 @@ derive_more = "0.99.17" mime = "0.3.17" reqwest = "0.11.18" clap = { version = "4.3.21", features = ["derive"] } +actix-cors = "0.6.4" diff --git a/tatoeba/src/main.rs b/tatoeba/src/main.rs index 630091d..3cf6f92 100644 --- a/tatoeba/src/main.rs +++ b/tatoeba/src/main.rs @@ -1,3 +1,4 @@ +use actix_cors::Cors; use utils::{ error::{Error, Result}, is_human, @@ -30,7 +31,11 @@ async fn root(request: HttpRequest) -> Result { #[actix_web::main] async fn main() -> std::io::Result<()> { - HttpServer::new(|| App::new().service(root)) + HttpServer::new(|| + App::new() + .service(root) + .wrap(Cors::permissive()) + ) .bind(("127.0.0.1", Args::parse().port))? .run() .await