Разрешаем CORS
This commit is contained in:
20
src/main/java/im/rosetta/CorsFilter.java
Normal file
20
src/main/java/im/rosetta/CorsFilter.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package im.rosetta;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import jakarta.ws.rs.container.ContainerRequestContext;
|
||||||
|
import jakarta.ws.rs.container.ContainerResponseContext;
|
||||||
|
import jakarta.ws.rs.container.ContainerResponseFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Разрешает CORS для всех доменов, чтобы клиенты могли обращаться к CDN напрямую из браузера
|
||||||
|
*/
|
||||||
|
public class CorsFilter implements ContainerResponseFilter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
|
||||||
|
throws IOException {
|
||||||
|
responseContext.getHeaders().add("Access-Control-Allow-Origin", "*");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ public class Main {
|
|||||||
ResourceConfig config = new ResourceConfig()
|
ResourceConfig config = new ResourceConfig()
|
||||||
.register(MultiPartFeature.class)
|
.register(MultiPartFeature.class)
|
||||||
.register(JacksonFeature.class)
|
.register(JacksonFeature.class)
|
||||||
|
.register(CorsFilter.class)
|
||||||
.register(new CdnResource(fileStore));
|
.register(new CdnResource(fileStore));
|
||||||
|
|
||||||
URI baseUri = URI.create("http://0.0.0.0:" + port + "/");
|
URI baseUri = URI.create("http://0.0.0.0:" + port + "/");
|
||||||
|
|||||||
Reference in New Issue
Block a user