Fix CORS policy

main
Elnu 1 year ago
parent 412ca4e538
commit ba6f91f672

17
Cargo.lock generated

@ -19,6 +19,21 @@ dependencies = [
"tracing", "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]] [[package]]
name = "actix-http" name = "actix-http"
version = "3.3.1" version = "3.3.1"
@ -893,6 +908,7 @@ dependencies = [
name = "images" name = "images"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"actix-cors",
"actix-web", "actix-web",
"clap", "clap",
"lazy_static", "lazy_static",
@ -1694,6 +1710,7 @@ dependencies = [
name = "tatoeba" name = "tatoeba"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"actix-cors",
"actix-web", "actix-web",
"clap", "clap",
"derive_more", "derive_more",

@ -40,7 +40,7 @@
pname = "tatoeba"; pname = "tatoeba";
version = "0.1.0"; version = "0.1.0";
buildAndTestSubdir = "tatoeba"; buildAndTestSubdir = "tatoeba";
cargoHash = "sha256-AK47aWFl4eLIVHy27iE2MX62+dfjidlMZT1/uzxQh4E="; cargoHash = "sha256-/mtl2kes7KmT3Vq+M/kpezhRTKLju3ZRXHFf2Zblczo=";
meta = meta // { meta = meta // {
description = "A proxy of the Tatoeba API with no CORS restrictions."; description = "A proxy of the Tatoeba API with no CORS restrictions.";
}; };
@ -49,7 +49,7 @@
pname = "images"; pname = "images";
version = "0.1.0"; version = "0.1.0";
buildAndTestSubdir = "images"; buildAndTestSubdir = "images";
cargoHash = "sha256-t7IDZJcpYc6eftNedFCRlJ+LQ1O2L2c/XjX8+YqZcjI="; cargoHash = "sha256-sxge+4WuT8iEVihiqvUAdS+n6U+NzEhfJ0p7lc+uLHE=";
meta = meta // { meta = meta // {
description = "An API for fetching images of a query, sourced from Microsoft Bing."; description = "An API for fetching images of a query, sourced from Microsoft Bing.";
}; };

@ -19,3 +19,4 @@ lazy_static = "1.4.0"
rand = "0.8.5" rand = "0.8.5"
serde_json = "1.0.104" serde_json = "1.0.104"
clap = { version = "4.3.21", features = ["derive"] } clap = { version = "4.3.21", features = ["derive"] }
actix-cors = "0.6.4"

@ -1,3 +1,4 @@
use actix_cors::Cors;
use utils::error::Result; use utils::error::Result;
use actix_web::{get, http::header, web, App, HttpResponse, HttpServer, Responder}; 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<impl Resp
#[actix_web::main] #[actix_web::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
HttpServer::new(|| { HttpServer::new(||
App::new() App::new()
.service(route_query_list) .service(route_query_list)
.service(route_query) .service(route_query)
.service(route_query_random) .service(route_query_random)
.service(route_query_index) .service(route_query_index)
}) .wrap(Cors::permissive())
)
.bind(("127.0.0.1", Args::parse().port))? .bind(("127.0.0.1", Args::parse().port))?
.run() .run()
.await .await

@ -16,3 +16,4 @@ derive_more = "0.99.17"
mime = "0.3.17" mime = "0.3.17"
reqwest = "0.11.18" reqwest = "0.11.18"
clap = { version = "4.3.21", features = ["derive"] } clap = { version = "4.3.21", features = ["derive"] }
actix-cors = "0.6.4"

@ -1,3 +1,4 @@
use actix_cors::Cors;
use utils::{ use utils::{
error::{Error, Result}, error::{Error, Result},
is_human, is_human,
@ -30,7 +31,11 @@ async fn root(request: HttpRequest) -> Result<impl Responder> {
#[actix_web::main] #[actix_web::main]
async fn main() -> std::io::Result<()> { 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))? .bind(("127.0.0.1", Args::parse().port))?
.run() .run()
.await .await

Loading…
Cancel
Save