From 9c92e7d1e91801ab509a27d5ec7adaddc4c8350a Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Tue, 27 Feb 2024 14:24:26 +0100 Subject: [PATCH] Ajout du CORS Pour le dev local + toastify + exmpl tout est dans le titre --- backend/build.gradle.kts | 2 +- .../herisson/Clyde/EndPoints/PingController.java | 4 +++- .../main/java/ovh/herisson/Clyde/JdbcConfig.java | 13 +++++++++++++ frontend/package-lock.json | 6 ++++++ frontend/package.json | 1 + frontend/src/App.vue | 5 +++++ 6 files changed, 29 insertions(+), 2 deletions(-) diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts index 66019d7..91c7679 100644 --- a/backend/build.gradle.kts +++ b/backend/build.gradle.kts @@ -19,7 +19,7 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-jdbc") implementation("org.springframework.boot:spring-boot-starter-mail") implementation("org.springframework.boot:spring-boot-starter-web") - implementation("org.springframework.session:spring-session-jdbc") + // implementation("org.springframework.session:spring-session-jdbc") developmentOnly("org.springframework.boot:spring-boot-devtools") developmentOnly("org.springframework.boot:spring-boot-docker-compose") runtimeOnly("org.postgresql:postgresql") diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/PingController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/PingController.java index f4f010d..b937610 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/PingController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/PingController.java @@ -1,16 +1,18 @@ package ovh.herisson.Clyde.EndPoints; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.RestController; import ovh.herisson.Clyde.Ping; @RestController +@CrossOrigin(origins = "http://localhost:5173") public class PingController { @GetMapping("/ping") public Ping ping(){ - return new Ping(1, "test"); + return new Ping(1, "pong"); } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/JdbcConfig.java b/backend/src/main/java/ovh/herisson/Clyde/JdbcConfig.java index 1b6da6a..56074f0 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/JdbcConfig.java +++ b/backend/src/main/java/ovh/herisson/Clyde/JdbcConfig.java @@ -5,6 +5,8 @@ import javax.sql.DataSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration public class JdbcConfig { @@ -20,4 +22,15 @@ public class JdbcConfig { return source; } + + @Bean + public WebMvcConfigurer corsConfigurer() { + return new WebMvcConfigurer() { + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/greeting-javaconfig").allowedOrigins("*"); + } + }; + } + } diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 82e0ddf..f324a1d 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -8,6 +8,7 @@ "name": "clyde", "version": "0.0.0", "dependencies": { + "toastify-js": "^1.12.0", "vue": "^3.4.15" }, "devDependencies": { @@ -2167,6 +2168,11 @@ "node": ">=14.0.0" } }, + "node_modules/toastify-js": { + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/toastify-js/-/toastify-js-1.12.0.tgz", + "integrity": "sha512-HeMHCO9yLPvP9k0apGSdPUWrUbLnxUKNFzgUoZp1PHCLploIX/4DSQ7V8H25ef+h4iO9n0he7ImfcndnN6nDrQ==" + }, "node_modules/tough-cookie": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.3.tgz", diff --git a/frontend/package.json b/frontend/package.json index f28af85..d4c73ab 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -10,6 +10,7 @@ "test:unit": "vitest" }, "dependencies": { + "toastify-js": "^1.12.0", "vue": "^3.4.15" }, "devDependencies": { diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 1d402bc..6fef200 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -1,5 +1,10 @@