Skip to content

Commit

Permalink
Closes#10 Add filter for CORS headers
Browse files Browse the repository at this point in the history
  • Loading branch information
aprajshekhar committed Oct 24, 2023
1 parent 070bc61 commit d97d7c2
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/main/java/com/gamedoora/gateway/util/CorsFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,15 @@ public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
ServerHttpRequest request = exchange.getRequest();
exchange.getResponse().getHeaders().
set("Access-Control-Allow-Origin", "*");

exchange.getResponse().getHeaders().
set("Access-Control-Allow-Credentials", "true");
exchange.getResponse().getHeaders().
set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT");
exchange.getResponse().getHeaders().
set("Access-Control-Max-Age", "3600");
exchange.getResponse().getHeaders().
set("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With, remember-me, Authorization");
return chain.filter(exchange);
}

private Mono<Void> onError(ServerWebExchange exchange, String err, HttpStatus httpStatus) {
ServerHttpResponse response = exchange.getResponse();
response.setStatusCode(httpStatus);
return response.setComplete();
}

private String getAuthHeader(ServerHttpRequest request) {
return request.getHeaders().getOrEmpty("Authorization").get(0);
}

private boolean isAuthMissing(ServerHttpRequest request) {
return !request.getHeaders().containsKey("Authorization");
}

}

0 comments on commit d97d7c2

Please sign in to comment.