diff options
author | Adrián Oliva <adrian.oliva@cimat.mx> | 2023-05-26 18:50:08 -0600 |
---|---|---|
committer | Adrián Oliva <adrian.oliva@cimat.mx> | 2023-05-26 18:50:08 -0600 |
commit | 5fccbca45f7ad6837f46b4f5967c06c85e588e8c (patch) | |
tree | 4e435405ed290e68214f7c4035dc65b541ebfcc3 /src/main/java/com/encora | |
parent | 4d0e671eb82c4ff6941905744dd10b856e16e725 (diff) | |
download | ToDo-App-BE-5fccbca45f7ad6837f46b4f5967c06c85e588e8c.tar.gz ToDo-App-BE-5fccbca45f7ad6837f46b4f5967c06c85e588e8c.zip |
CORS problem.
It now accepts requests from outside the URL. See
https://stackoverflow.com/a/64137023 and
https://stackoverflow.com/a/46065200.
Diffstat (limited to '')
-rw-r--r-- | src/main/java/com/encora/Main.java | 14 |
1 files changed, 14 insertions, 0 deletions
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) { |