From 3a7e1f26b05b217dc8a2a83721400ce4a3843b97 Mon Sep 17 00:00:00 2001 From: MiniDigger Date: Mon, 21 Mar 2022 16:01:15 +0100 Subject: [PATCH] fix cors error --- src/main/java/io/papermc/hangar/config/WebConfig.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/papermc/hangar/config/WebConfig.java b/src/main/java/io/papermc/hangar/config/WebConfig.java index 1c6fe03b3..49e091ccf 100644 --- a/src/main/java/io/papermc/hangar/config/WebConfig.java +++ b/src/main/java/io/papermc/hangar/config/WebConfig.java @@ -29,6 +29,7 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConvert import org.springframework.web.client.RestTemplate; import org.springframework.web.filter.ShallowEtagHeaderFilter; import org.springframework.web.method.support.HandlerMethodArgumentResolver; +import org.springframework.web.servlet.config.annotation.CorsRegistration; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; @@ -70,7 +71,12 @@ public class WebConfig extends WebMvcConfigurationSupport { @Override protected void addCorsMappings(CorsRegistry registry) { - registry.addMapping("/api/internal/**").allowedOrigins(hangarConfig.isDev() ? "http://localhost:3000" : hangarConfig.getBaseUrl()); + CorsRegistration corsRegistration = registry.addMapping("/api/internal/**"); + if (hangarConfig.isDev()) { + corsRegistration.allowedOrigins("http://localhost:3000", "http://localhost:3333"); + } else { + corsRegistration.allowedOrigins(hangarConfig.getBaseUrl()); + } } @Bean