From 5fccbca45f7ad6837f46b4f5967c06c85e588e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Oliva?= Date: Fri, 26 May 2023 18:50:08 -0600 Subject: CORS problem. It now accepts requests from outside the URL. See https://stackoverflow.com/a/64137023 and https://stackoverflow.com/a/46065200. --- src/main/java/com/encora/Main.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/com/encora/Main.java b/src/main/java/com/encora/Main.java index ac2a609..14026af 100644 --- a/src/main/java/com/encora/Main.java +++ b/src/main/java/com/encora/Main.java @@ -2,9 +2,12 @@ package com.encora; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; import org.springframework.data.domain.Sort; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import java.util.Date; import java.util.List; @@ -14,6 +17,17 @@ import java.util.Objects; @RestController @RequestMapping("v1") public class Main { + @Bean + public WebMvcConfigurer corsConfigurer() { + return new WebMvcConfigurer() { + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**").allowedOrigins("*"); + } + }; + } + + private final ToDosRepository toDosRepository; public Main(ToDosRepository toDosRepository) { -- cgit v1.2.3