From 907e4b96b27462d65c7e8599623e01e08099cf1b Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Thu, 9 Jun 2022 21:36:28 +0430 Subject: CORS fix --- spring-front/src/config.js | 4 ++-- .../java/com/terminaldweller/doc/DocController.java | 7 ++++++- .../com/terminaldweller/main/DevConfiguration.java | 21 --------------------- 3 files changed, 8 insertions(+), 24 deletions(-) delete mode 100644 src/main/java/com/terminaldweller/main/DevConfiguration.java diff --git a/spring-front/src/config.js b/spring-front/src/config.js index b85e2d1..7c2f8a5 100644 --- a/spring-front/src/config.js +++ b/spring-front/src/config.js @@ -1,4 +1,4 @@ export const mdrtlConfig = { - // serverURL: "https://localhost:9080/api/v1/doc", - serverURL: "https://editorsave.terminaldweller.com/api/v1/doc", + serverURL: "https://localhost:9080/api/v1/doc", + // serverURL: "https://editorsave.terminaldweller.com/api/v1/doc", }; diff --git a/src/main/java/com/terminaldweller/doc/DocController.java b/src/main/java/com/terminaldweller/doc/DocController.java index f45ba52..a6a1734 100644 --- a/src/main/java/com/terminaldweller/doc/DocController.java +++ b/src/main/java/com/terminaldweller/doc/DocController.java @@ -16,7 +16,8 @@ import org.springframework.web.bind.annotation.RestController; /** The document controller class. */ @RestController -@CrossOrigin(origins = "https://localhost:7080, https://editor.terminaldweller.com") +// @CrossOrigin(origins = {"https://localhost:7080, https://editor.terminaldweller.com"}) +// @CrossOrigin(origins = "https://localhost:7080") @RequestMapping(path = "api/v1/doc") public class DocController { private final DocService docService; @@ -26,22 +27,26 @@ public class DocController { this.docService = docService; } + @CrossOrigin(origins = "https://localhost:7080") @GetMapping(path = "{Id}") public Optional getDocs(@PathVariable("Id") Long id) { return docService.getDocs(id); } + @CrossOrigin(origins = "https://localhost:7080") @PostMapping(path = "{Id}") @ResponseStatus(HttpStatus.CREATED) public void postDocs(@PathVariable("Id") Long id, @RequestBody Doc doc) { docService.addNewDoc(id, doc); } + @CrossOrigin(origins = "https://localhost:7080") @DeleteMapping(path = "{Id}") public void deleteDocs(@PathVariable("Id") Long id) { docService.deleteDoc(id); } + @CrossOrigin(origins = "https://localhost:7080") @PutMapping(path = "{Id}") public void updatDoc(@RequestBody Doc doc, @PathVariable("Id") long id) { docService.updateDoc(doc, id); diff --git a/src/main/java/com/terminaldweller/main/DevConfiguration.java b/src/main/java/com/terminaldweller/main/DevConfiguration.java deleted file mode 100644 index 6f0137b..0000000 --- a/src/main/java/com/terminaldweller/main/DevConfiguration.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.terminaldweller; - -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.web.servlet.config.annotation.CorsRegistry; -// import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -@Configuration -// @EnableWebMvc -@Profile("development") -public class DevConfiguration implements WebMvcConfigurer { - - @Override - public void addCorsMappings(CorsRegistry registry) { - registry - .addMapping("/**") - .allowedOrigins("https://localhost:7080, https://editor.terminaldweller.com") - .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS"); - } -} -- cgit v1.2.3