From 690309b8099c8e8b82f76bf2edd301f45bc5f419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Fri, 13 May 2022 13:36:23 +0200 Subject: [PATCH] feat: ajout d'un truc CORS ? --- src/main/java/com/pixels/CorsFilter.java | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/com/pixels/CorsFilter.java diff --git a/src/main/java/com/pixels/CorsFilter.java b/src/main/java/com/pixels/CorsFilter.java new file mode 100644 index 0000000..7e7c713 --- /dev/null +++ b/src/main/java/com/pixels/CorsFilter.java @@ -0,0 +1,27 @@ +package com.pixels; + +import java.io.IOException; + +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerResponseContext; +import javax.ws.rs.container.ContainerResponseFilter; +import javax.ws.rs.ext.Provider; + +@Provider +public class CorsFilter implements ContainerResponseFilter { + + @Override + public void filter(ContainerRequestContext requestContext, + ContainerResponseContext responseContext) throws IOException { + responseContext.getHeaders().add( + "Access-Control-Allow-Origin", "*"); + responseContext.getHeaders().add( + "Access-Control-Allow-Credentials", "true"); + responseContext.getHeaders().add( + "Access-Control-Allow-Headers", + "origin, content-type, accept, authorization"); + responseContext.getHeaders().add( + "Access-Control-Allow-Methods", + "GET, POST, PUT, DELETE, OPTIONS, HEAD"); + } +}