Skip to content

Commit

Permalink
Return correct AccessControlAllowOrigin header
Browse files Browse the repository at this point in the history
Fixes #3
  • Loading branch information
glyn committed Jun 28, 2024
1 parent 544dc68 commit 3872078
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use axum::{
};
use axum_extra::extract::Query;
use fluent_uri::Uri;
use hyper::header::CONTENT_TYPE;
use hyper::header::{ACCESS_CONTROL_ALLOW_ORIGIN, CONTENT_TYPE};
use serde::Deserialize;
use std::fs;
use std::io;
Expand Down Expand Up @@ -115,6 +115,7 @@ async fn handler(State(state): State<ServerState>, Query(params): Query<Params>)
Response::builder()
.status(StatusCode::OK)
.header(CONTENT_TYPE, "application/jrd+json")
.header(ACCESS_CONTROL_ALLOW_ORIGIN, "*")
.body(Body::from(body))
.unwrap()
} else {
Expand Down Expand Up @@ -481,6 +482,10 @@ mod tests {
response.headers().get(CONTENT_TYPE).unwrap(),
"application/jrd+json"
);
assert_eq!(
response.headers().get(ACCESS_CONTROL_ALLOW_ORIGIN).unwrap(),
"*"
);

let body = response.into_body().collect().await.unwrap().to_bytes();
let actual: Value = serde_json::from_str(str::from_utf8(&body[..]).unwrap()).unwrap();
Expand Down

0 comments on commit 3872078

Please sign in to comment.