Add CORS configuration to allow cross-origin requests

This commit is contained in:
Lemonochrme 2024-12-16 18:04:26 +01:00
parent f9c4ca5033
commit 6a345d0b55

View file

@ -5,6 +5,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;
@ -28,6 +30,18 @@ public class RequestServiceApplication {
private final RestTemplate restTemplate = new RestTemplate();
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedOrigins("*")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*");
}
};
}
// Create a new help request
@PostMapping
public HelpRequest createRequest(@RequestBody HelpRequest request) {