I'm trying to build out a simple backend with Rust, but I keep running into a CORS error.
My react frontend says:
Access to XMLHttpRequest at 'http://127.0.0.1:3002/auth' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Here's my backend code:
// Route Config //
pub fn routes(cfg: &mut web::ServiceConfig) {
cfg.route("/auth", web::get().to(auth_handler));
}
// Handler Config //
async fn auth_handler() -> impl Responder {
HttpResponse::Ok().json("Works")
}
#[actix_rt::main]
async fn main() -> io::Result<()> {
let app = move || App::new().configure(routes);
let _cors = Cors::permissive();
HttpServer::new(app).bind("127.0.0.1:3002")?.run().await
}
To my understanding, the CORS::permissive() function should allow all cross site interactions to work. Did I misunderstand the docs, or did I implement it wrong?