debug build cors rules
This commit is contained in:
parent
7945636b39
commit
6d0c2526c9
4 changed files with 1355 additions and 1 deletions
1327
Cargo.lock
generated
1327
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -1,2 +1,3 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
|
resolver = "2"
|
||||||
members = ["crates/backend"]
|
members = ["crates/backend"]
|
||||||
|
|
|
@ -2,3 +2,7 @@
|
||||||
name = "backend"
|
name = "backend"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
actix-web = "4"
|
||||||
|
actix-cors = "0.7"
|
||||||
|
|
|
@ -1 +1,23 @@
|
||||||
fn main() {}
|
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
|
||||||
|
|
||||||
|
#[actix_web::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
println!("Running debug build -> enabling permissive CORS");
|
||||||
|
|
||||||
|
HttpServer::new(move || {
|
||||||
|
let cors = if cfg!(debug_assertions) {
|
||||||
|
actix_cors::Cors::permissive()
|
||||||
|
} else {
|
||||||
|
actix_cors::Cors::default()
|
||||||
|
};
|
||||||
|
App::new().wrap(cors).route("/", web::get().to(index))
|
||||||
|
})
|
||||||
|
.bind(("127.0.0.1", 8080))?
|
||||||
|
.run()
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn index() -> impl Responder {
|
||||||
|
HttpResponse::Ok().body("API Test Response")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue