generated from ElnuDev/rust-project
Fix CORS policy
This commit is contained in:
parent
412ca4e538
commit
ba6f91f672
6 changed files with 31 additions and 5 deletions
17
Cargo.lock
generated
17
Cargo.lock
generated
|
@ -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",
|
||||
|
|
|
@ -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.";
|
||||
};
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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<impl Resp
|
|||
|
||||
#[actix_web::main]
|
||||
async fn main() -> 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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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<impl Responder> {
|
|||
|
||||
#[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
|
||||
|
|
Loading…
Add table
Reference in a new issue