Skip to content

Commit

Permalink
fix: fixed OPTIONS catchers with rocket_cors (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrolez committed Jul 15, 2021
1 parent 3ebdf06 commit 25b2032
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
18 changes: 8 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions aw-server/src/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ pub fn build_rocket(server_state: ServerState, config: AWConfig) -> rocket::Rock
"Starting aw-server-rust at {}:{}",
config.address, config.port
);
let cors = cors::cors(&config);
rocket::custom(config.to_rocket_config())
.attach(cors.clone())
.manage(cors)
.manage(server_state)
.manage(config)
.mount(
"/",
routes![
Expand Down Expand Up @@ -120,7 +125,5 @@ pub fn build_rocket(server_state: ServerState, config: AWConfig) -> rocket::Rock
settings::setting_delete
],
)
.attach(cors::cors(&config))
.manage(server_state)
.manage(config)
.mount("/", rocket_cors::catch_all_options_routes())
}
13 changes: 13 additions & 0 deletions aw-server/tests/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,4 +655,17 @@ mod api_tests {
let res = client.get("/api/0/settings/test_key").dispatch();
assert_eq!(res.status(), rocket::http::Status::NotFound);
}

#[test]
fn test_cors_catching() {
let server = setup_testserver();
let client = rocket::local::Client::new(server).expect("valid instance");

let mut res = client
.options("/api/0/buckets/")
.header(ContentType::JSON)
.dispatch();
debug!("{:?}", res.body_string());
assert_eq!(res.status(), rocket::http::Status::Ok);
}
}

0 comments on commit 25b2032

Please sign in to comment.