aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2022-06-10 05:55:24 +0000
committerterminaldweller <thabogre@gmail.com>2022-06-10 05:55:24 +0000
commit1ce4b8f49ee9a7611413dd017af47629a535edf5 (patch)
treec3f4ece2e8d2723bf64c268d4396409149fa994b
parentCORS fix (diff)
downloadmdrtl-1ce4b8f49ee9a7611413dd017af47629a535edf5.tar.gz
mdrtl-1ce4b8f49ee9a7611413dd017af47629a535edf5.zip
CORS fix
-rw-r--r--docker-compose.yaml6
-rw-r--r--spring-front/src/config.js4
-rw-r--r--src/main/java/com/terminaldweller/doc/DocController.java6
-rw-r--r--src/main/java/com/terminaldweller/main/DevConfiguration.java24
4 files changed, 30 insertions, 10 deletions
diff --git a/docker-compose.yaml b/docker-compose.yaml
index b1bb081..d17e75a 100644
--- a/docker-compose.yaml
+++ b/docker-compose.yaml
@@ -1,4 +1,4 @@
-version: "3"
+version: "3.4"
services:
server:
image: spring
@@ -8,8 +8,8 @@ services:
- "9080:8443"
networks:
- springnet
- cap_drop:
- - ALL
+ # cap_drop:
+ # - ALL
environment:
- DOCKER_DEPLOYMENT_TYPE=deployment
# restart: unless-stopped
diff --git a/spring-front/src/config.js b/spring-front/src/config.js
index 7c2f8a5..b85e2d1 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 a6a1734..53f2748 100644
--- a/src/main/java/com/terminaldweller/doc/DocController.java
+++ b/src/main/java/com/terminaldweller/doc/DocController.java
@@ -17,7 +17,7 @@ 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")
+@CrossOrigin(origins = "https://editor.terminaldweller.com", maxAge = 3600)
@RequestMapping(path = "api/v1/doc")
public class DocController {
private final DocService docService;
@@ -27,26 +27,22 @@ public class DocController {
this.docService = docService;
}
- @CrossOrigin(origins = "https://localhost:7080")
@GetMapping(path = "{Id}")
public Optional<Doc> 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
new file mode 100644
index 0000000..0b253df
--- /dev/null
+++ b/src/main/java/com/terminaldweller/main/DevConfiguration.java
@@ -0,0 +1,24 @@
+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("/api/**")
+ .allowedOrigins("https://editor.terminaldweller.com")
+ .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
+ .allowedHeaders("*")
+ .maxAge(3600);
+ // .allowedOrigins("https://localhost:7080", "https://editor.terminaldweller.com")
+ }
+}