Fix Access-Control-Expose-Headers header
This commit is contained in:
parent
53ace3bf57
commit
450e47bcef
2 changed files with 6 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
||||||
use actix_cors::Cors;
|
use actix_cors::Cors;
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
|
http::header,
|
||||||
web,
|
web,
|
||||||
App, HttpServer,
|
App, HttpServer,
|
||||||
dev::Service,
|
dev::Service,
|
||||||
|
@ -92,6 +93,11 @@ async fn main() -> std::io::Result<()> {
|
||||||
.allow_any_header()
|
.allow_any_header()
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
let cors_config = cors_config
|
||||||
|
// Link header needs to be explicitly exposed
|
||||||
|
// because expose_any_header doesn't work
|
||||||
|
// https://github.com/actix/actix-extras/issues/192
|
||||||
|
.expose_headers(vec![header::LINK]);
|
||||||
let mut app = App::new()
|
let mut app = App::new()
|
||||||
.wrap(cors_config)
|
.wrap(cors_config)
|
||||||
.wrap(ActixLogger::new("%r : %s : %{r}a"))
|
.wrap(ActixLogger::new("%r : %s : %{r}a"))
|
||||||
|
|
|
@ -30,9 +30,6 @@ pub fn get_paginated_response(
|
||||||
);
|
);
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.append_header(("Link", pagination_header))
|
.append_header(("Link", pagination_header))
|
||||||
// Link header needs to be exposed
|
|
||||||
// https://github.com/actix/actix-extras/issues/192
|
|
||||||
.append_header(("Access-Control-Expose-Headers", "Link"))
|
|
||||||
.json(items)
|
.json(items)
|
||||||
} else {
|
} else {
|
||||||
HttpResponse::Ok().json(items)
|
HttpResponse::Ok().json(items)
|
||||||
|
|
Loading…
Reference in a new issue