diff --git a/backend/pom.xml b/backend/pom.xml index 7d9e4e4c98..8f94e67f1f 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -63,7 +63,7 @@ org.springframework.boot - spring-boot-starter-jetty + spring-boot-starter-undertow org.springframework.boot diff --git a/backend/src/main/java/io/metersphere/config/HTTPSConfig.java b/backend/src/main/java/io/metersphere/config/HTTPSConfig.java new file mode 100644 index 0000000000..9a4b267c4d --- /dev/null +++ b/backend/src/main/java/io/metersphere/config/HTTPSConfig.java @@ -0,0 +1,52 @@ +package io.metersphere.config; + + +import io.undertow.Undertow; +import io.undertow.UndertowOptions; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + + +@Configuration +@ConditionalOnProperty(name = "server.ssl.enabled", havingValue = "true") +public class HTTPSConfig { + + /** + * http服务端口 + */ + @Value("${server.http.port}") + private Integer httpPort; + + /** + * https服务端口 + */ + @Value("${server.port}") + private Integer httpsPort; + + + @Bean + public ServletWebServerFactory undertowFactory() { + UndertowServletWebServerFactory undertowFactory = new UndertowServletWebServerFactory(); + undertowFactory.addBuilderCustomizers((Undertow.Builder builder) -> { + builder.addHttpListener(httpPort, "0.0.0.0"); + // 开启HTTP2 + builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true); + }); + // 暂不开启自动跳转 +// undertowFactory.addDeploymentInfoCustomizers(deploymentInfo -> { +// // 开启HTTP自动跳转至HTTPS +// deploymentInfo.addSecurityConstraint(new SecurityConstraint() +// .addWebResourceCollection(new WebResourceCollection().addUrlPattern("/*")) +// .setTransportGuaranteeType(TransportGuaranteeType.CONFIDENTIAL) +// .setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.PERMIT)) +// .setConfidentialPortManager(exchange -> httpsPort); +// }); + return undertowFactory; + } + +} + diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index 0c0607a01e..4757f780f5 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -1,6 +1,14 @@ spring.application.name=metersphere -server.port=8081 +server.http.port=8081 +server.port=8443 +# http2 +server.http2.enabled=true +server.ssl.enabled=true +server.ssl.key-store-type=PKCS12 +server.ssl.key-store=classpath:localhost.p12 +server.ssl.key-store-password=123456 +server.ssl.key-alias=localhost # Hikari spring.datasource.type=com.zaxxer.hikari.HikariDataSource diff --git a/backend/src/main/resources/localhost.p12 b/backend/src/main/resources/localhost.p12 new file mode 100644 index 0000000000..ca0fb6fa4b Binary files /dev/null and b/backend/src/main/resources/localhost.p12 differ diff --git a/frontend/vue.config.js b/frontend/vue.config.js index 1478f26db5..b02f3830fd 100644 --- a/frontend/vue.config.js +++ b/frontend/vue.config.js @@ -13,7 +13,7 @@ module.exports = { //1.8需求:增加分享功能,不登陆即可看到文档页面。所以代理设置增加了(?!/document)文档页面的相关信息 // ['^(?!/login)']: { ['^((?!/login)(?!/document))']: { - target: 'http://localhost:8081', + target: 'https://localhost:8443', ws: true, }, }