From 411982971a6e74d712c24bb0870dd94df5c29bf2 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Wed, 20 Mar 2024 11:15:13 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E9=A1=B9=E7=9B=AE=E7=AE=A1=E7=90=86):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96mock=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/project/service/EnvironmentService.java | 8 +++++++- .../environmental/components/envParams/HttpTab.vue | 8 ++++---- .../components/envParams/popUp/AddHttpDrawer.vue | 8 +++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/EnvironmentService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/EnvironmentService.java index d6ee914fb6..f86dedd1f2 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/EnvironmentService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/EnvironmentService.java @@ -92,6 +92,8 @@ public class EnvironmentService extends MoveNodeService { private static final String PASSWORD = "password"; private static final String PATH = "/project/environment/import"; private static final String MOCK_EVN_SOCKET = "/mock-server/"; + private static final String HTTP = "http://"; + private static final String HTTPS = "https://"; public List getDriverOptions(String organizationId) { return jdbcDriverPluginService.getJdbcDriverOption(organizationId); @@ -205,7 +207,11 @@ public class EnvironmentService extends MoveNodeService { String baseUrl = baseSystemConfigDTO.getUrl(); if (StringUtils.isNotEmpty(baseUrl)) { Project project = projectMapper.selectByPrimaryKey(environment.getProjectId()); - environmentInfoDTO.getConfig().getHttpConfig().getFirst().setHostname(StringUtils.join(baseUrl, MOCK_EVN_SOCKET, project.getNum())); + String domain = baseUrl.replace(HTTP, StringUtils.EMPTY).replace(HTTPS, StringUtils.EMPTY); + String protocol = baseUrl.substring(0, baseUrl.indexOf(domain) -3 ); + environmentInfoDTO.getConfig().getHttpConfig().getFirst().setId(IDGenerator.nextStr()); + environmentInfoDTO.getConfig().getHttpConfig().getFirst().setProtocol(protocol); + environmentInfoDTO.getConfig().getHttpConfig().getFirst().setHostname(StringUtils.join(domain, MOCK_EVN_SOCKET, project.getNum())); environmentInfoDTO.getConfig().getHttpConfig().getFirst().setUrl(StringUtils.join(baseUrl, MOCK_EVN_SOCKET, project.getNum())); } } diff --git a/frontend/src/views/project-management/environmental/components/envParams/HttpTab.vue b/frontend/src/views/project-management/environmental/components/envParams/HttpTab.vue index 7f6e74454e..94661d6e40 100644 --- a/frontend/src/views/project-management/environmental/components/envParams/HttpTab.vue +++ b/frontend/src/views/project-management/environmental/components/envParams/HttpTab.vue @@ -46,7 +46,9 @@