From 03d4f74389e90233c98ac3bcc4b36bb9127da1e2 Mon Sep 17 00:00:00 2001 From: tee8z Date: Sun, 18 Aug 2024 18:35:07 -0400 Subject: [PATCH] fixing cors issues with the API post endpoint (#28) --- Cargo.lock | 4 ++-- daemon/Cargo.toml | 2 +- oracle/Cargo.toml | 2 +- oracle/src/startup.rs | 5 +++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e5e4251..a02d8a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1057,7 +1057,7 @@ dependencies = [ [[package]] name = "daemon" -version = "1.0.2" +version = "1.0.3" dependencies = [ "anyhow", "arrow", @@ -2287,7 +2287,7 @@ dependencies = [ [[package]] name = "oracle" -version = "1.0.2" +version = "1.0.3" dependencies = [ "anyhow", "axum", diff --git a/daemon/Cargo.toml b/daemon/Cargo.toml index cedd2dc..ff1fbde 100644 --- a/daemon/Cargo.toml +++ b/daemon/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "daemon" -version = "1.0.2" +version = "1.0.3" edition = "2021" repository = "https://github.com/tee8z/noaa-data-pipeline" diff --git a/oracle/Cargo.toml b/oracle/Cargo.toml index 06e3d75..bdcbc43 100644 --- a/oracle/Cargo.toml +++ b/oracle/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oracle" -version = "1.0.2" +version = "1.0.3" edition = "2021" repository = "https://github.com/tee8z/noaa-data-pipeline" diff --git a/oracle/src/startup.rs b/oracle/src/startup.rs index 37d84da..da0a993 100644 --- a/oracle/src/startup.rs +++ b/oracle/src/startup.rs @@ -15,7 +15,7 @@ use axum::{ routing::{get, post}, Router, }; -use hyper::Method; +use hyper::{Method, header::{ACCEPT, CONTENT_TYPE}}; use log::info; use std::sync::Arc; use tower_http::{ @@ -103,7 +103,8 @@ pub fn app(app_state: AppState) -> Router { let serve_dir = ServeDir::new("ui").not_found_service(ServeFile::new(app_state.ui_dir.clone())); let cors = CorsLayer::new() // allow `GET` and `POST` when accessing the resource - .allow_methods([Method::GET, Method::POST]) + .allow_methods([Method::GET, Method::POST, Method::OPTIONS]) + .allow_headers([ACCEPT,CONTENT_TYPE]) // allow requests from any origin .allow_origin(Any); Router::new()