[feat] WIP - add CORS to http endpoint
@@ -107,15 +107,17 @@ pub async fn run(config: Config, startup: &mut dyn Startup) -> anyhow::Result<()
}));
}
+ let main = HttpBuilder::new(config.http, Some(startup.runtime_config()), move |cfg| {
let cors = Cors::default()
- .allowed_origin("drogue.io")
- .allowed_origin_fn(|origin, _req_head| origin.as_bytes().starts_with(b"localhost"))
+ .allowed_origin("http://127.0.0.1:2603")
+ .allowed_origin_fn(|origin, _req_head| origin.as_bytes().ends_with(b"drogue.cloud"))
.allowed_methods(vec!["POST"])
- .allowed_headers(vec![http::header::AUTHORIZATION])
- .allowed_header(http::header::CONTENT_TYPE)
+ .allowed_headers(vec![
+ http::header::AUTHORIZATION,
+ http::header::CONTENT_TYPE,
+ ])
.max_age(3600);
- let main = HttpBuilder::new(config.http, Some(startup.runtime_config()), move |cfg| {
cfg.app_data(web::Data::new(sender.clone()))
.app_data(web::Data::new(http_server_commands.clone()))
.app_data(web::Data::new(device_authenticator.clone()))
@@ -123,7 +125,7 @@ pub async fn run(config: Config, startup: &mut dyn Startup) -> anyhow::Result<()
// the standard endpoint
.service(
web::scope("/v1")
- .wrap(cors.clone())
+ .wrap(cors)
.service(
web::resource("/{channel}").route(web::post().to(telemetry::publish_plain)),
)
@@ -135,7 +137,6 @@ pub async fn run(config: Config, startup: &mut dyn Startup) -> anyhow::Result<()
// The Things Network variant
.service(
web::scope("/ttn")
- .wrap(cors)
.route("/", web::post().to(ttn::publish_v2))
.route("/v2", web::post().to(ttn::publish_v2))
.route("/v3", web::post().to(ttn::publish_v3)),
