diff --git a/src/items.rs b/src/items.rs index 09e0d08..b592388 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1,4 +1,4 @@ -use actix_web::{get, web, HttpResponse, Responder}; +use actix_web::{get, web, HttpResponse, Responder, options}; use actix_web::web::Data; use serde_json::to_string; use sqlx::query_as; @@ -16,7 +16,7 @@ async fn get_item(query: web::Query, app_state: Data) -> imp if json.is_err() { return HttpResponse::InternalServerError().finish(); } - HttpResponse::Ok().body(json.unwrap()) + HttpResponse::Ok().append_header(("Access-Control-Allow-Origin", "*")).body(json.unwrap()) } #[get("/items")] diff --git a/src/main.rs b/src/main.rs index 4641805..144c2ac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,10 +2,12 @@ mod users; mod cases; mod items; mod types; +mod utils; use users::*; use cases::*; use items::*; +use utils::*; use actix_web::web::Data; use actix_web::{App, HttpServer}; @@ -17,6 +19,7 @@ struct AppState { token_expiration: u64, } + #[actix_web::main] async fn main() -> std::io::Result<()> { let pool = SqlitePool::connect("sqlite:database.db") @@ -37,6 +40,7 @@ async fn main() -> std::io::Result<()> { .service(get_items) .service(get_case_items) .service(get_item_cases) + .service(options) .app_data(app_state.clone()) }) .bind(("127.0.0.1", 8000))?