From b650c1eae02cb8f3516bae0969e1c9c0783c646e Mon Sep 17 00:00:00 2001 From: Quentin Guillemin Date: Mon, 5 Feb 2024 18:00:34 +0100 Subject: [PATCH] feat: use configuration api path for frontend properties --- .env.example | 2 - .env.production | 2 - .../configuration/CollabsoftProperties.java | 3 ++ .../configuration/bean/FrontProperties.java | 46 +++++++++++++++++++ .../web/rest/ConfigurationController.java | 13 +++++- .../config/application-prod.example.yml | 7 +++ src/main/resources/config/application.yml | 7 +++ .../webapp/src/stores/configurationStore.ts | 1 + .../webapp/src/types/configurationType.ts | 4 +- .../app/tldraw/CollaborativeTldrawView.vue | 10 ++-- 10 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 src/main/java/fr/recia/collabsoft/configuration/bean/FrontProperties.java diff --git a/.env.example b/.env.example index fa6c8861..ef92b3b9 100644 --- a/.env.example +++ b/.env.example @@ -3,8 +3,6 @@ VITE_API_URI="/" VITE_NEXTCLOUD_URI="/nextcloud" VITE_AXIOS_TIMEOUT=10000 -VITE_WEBSOCKET_API_URL="" - VITE_USER_INFO_API_URI="" VITE_PROXY_API_URL="http://localhost:8090" diff --git a/.env.production b/.env.production index 56ced95b..d7d38b98 100644 --- a/.env.production +++ b/.env.production @@ -2,6 +2,4 @@ VITE_BASE_URI="/collabsoft" VITE_API_URI="/collabsoft" VITE_AXIOS_TIMEOUT=10000 -VITE_WEBSOCKET_API_URL="" - VITE_USER_INFO_API_URI="/portail/api/v5-1/userinfo?claims=private,name&groups=" diff --git a/src/main/java/fr/recia/collabsoft/configuration/CollabsoftProperties.java b/src/main/java/fr/recia/collabsoft/configuration/CollabsoftProperties.java index 1db1d4bf..b6745e79 100644 --- a/src/main/java/fr/recia/collabsoft/configuration/CollabsoftProperties.java +++ b/src/main/java/fr/recia/collabsoft/configuration/CollabsoftProperties.java @@ -17,6 +17,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import fr.recia.collabsoft.configuration.bean.CorsProperties; +import fr.recia.collabsoft.configuration.bean.FrontProperties; import fr.recia.collabsoft.configuration.bean.SecurityProperties; import fr.recia.collabsoft.configuration.bean.SoffitProperties; import fr.recia.collabsoft.configuration.bean.StorageProperties; @@ -39,6 +40,7 @@ public class CollabsoftProperties { private CorsProperties cors = new CorsProperties(); + private FrontProperties front = new FrontProperties(); private SecurityProperties security = new SecurityProperties(); private SoffitProperties soffit = new SoffitProperties(); private StorageProperties storage = new StorageProperties(); @@ -52,6 +54,7 @@ private void init() throws JsonProcessingException { public String toString() { return "{\n" + cors + ",\n" + + front + ",\n" + security + ",\n" + soffit + "\n" + storage diff --git a/src/main/java/fr/recia/collabsoft/configuration/bean/FrontProperties.java b/src/main/java/fr/recia/collabsoft/configuration/bean/FrontProperties.java new file mode 100644 index 00000000..de1856eb --- /dev/null +++ b/src/main/java/fr/recia/collabsoft/configuration/bean/FrontProperties.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2023 GIP-RECIA, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package fr.recia.collabsoft.configuration.bean; + +import lombok.Data; + +@Data +public class FrontProperties { + + private WebsocketProperties websocket = new WebsocketProperties(); + + @Data + public static class WebsocketProperties { + + private String url; + + @Override + public String toString() { + return "{" + + "\n\t\t\"url\": \"" + url + "\"" + + "\n}"; + } + + } + + @Override + public String toString() { + return "\"FrontProperties\": {" + + "\n\t\"websocket\": \"" + websocket + "\"" + + "\n}"; + } + +} diff --git a/src/main/java/fr/recia/collabsoft/web/rest/ConfigurationController.java b/src/main/java/fr/recia/collabsoft/web/rest/ConfigurationController.java index 9b190842..4a9ea9c9 100644 --- a/src/main/java/fr/recia/collabsoft/web/rest/ConfigurationController.java +++ b/src/main/java/fr/recia/collabsoft/web/rest/ConfigurationController.java @@ -15,21 +15,32 @@ */ package fr.recia.collabsoft.web.rest; +import fr.recia.collabsoft.configuration.CollabsoftProperties; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.HashMap; +import java.util.Map; + @Slf4j @RestController @RequestMapping(value = "/api/config") public class ConfigurationController { + @Autowired + private CollabsoftProperties collabsoftProperties; + @GetMapping public ResponseEntity getConfiguration() { - return new ResponseEntity<>(HttpStatus.OK); + Map data = new HashMap<>(); + data.put("websocketApiUrl", collabsoftProperties.getFront().getWebsocket().getUrl()); + + return new ResponseEntity<>(data, HttpStatus.OK); } } diff --git a/src/main/resources/config/application-prod.example.yml b/src/main/resources/config/application-prod.example.yml index 67657711..012f2a2c 100644 --- a/src/main/resources/config/application-prod.example.yml +++ b/src/main/resources/config/application-prod.example.yml @@ -21,3 +21,10 @@ app: soffit: jwt-signature-key: '' + + storage: + location: '' + + front: + websocket: + url: '' diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index 7a787224..d6591a25 100644 --- a/src/main/resources/config/application.yml +++ b/src/main/resources/config/application.yml @@ -64,3 +64,10 @@ app: soffit: jwt-signature-key: '' + + storage: + location: '' + + front: + websocket: + url: '' diff --git a/src/main/webapp/src/stores/configurationStore.ts b/src/main/webapp/src/stores/configurationStore.ts index 7c0f9fb1..43d40c0e 100644 --- a/src/main/webapp/src/stores/configurationStore.ts +++ b/src/main/webapp/src/stores/configurationStore.ts @@ -86,6 +86,7 @@ export const useConfigurationStore = defineStore('configuration', () => { const isSettings = ref(false); return { + configuration, init, isReady, user, diff --git a/src/main/webapp/src/types/configurationType.ts b/src/main/webapp/src/types/configurationType.ts index 55d68169..284ea527 100644 --- a/src/main/webapp/src/types/configurationType.ts +++ b/src/main/webapp/src/types/configurationType.ts @@ -1 +1,3 @@ -export type Configuration = {}; +export type Configuration = { + websocketApiUrl: string; +}; diff --git a/src/main/webapp/src/views/app/tldraw/CollaborativeTldrawView.vue b/src/main/webapp/src/views/app/tldraw/CollaborativeTldrawView.vue index 95d27f77..fcec1a0b 100644 --- a/src/main/webapp/src/views/app/tldraw/CollaborativeTldrawView.vue +++ b/src/main/webapp/src/views/app/tldraw/CollaborativeTldrawView.vue @@ -1,5 +1,6 @@