From 83ef71276a4d6301b6fe726666b725d23fa1e53a Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Tue, 12 Oct 2021 13:42:46 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=BC=80=E5=90=AFhttp2=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81http=E5=92=8Chttps=E7=AB=AF=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/pom.xml | 2 +- .../io/metersphere/config/HTTPSConfig.java | 52 ++++++++++++++++++ .../src/main/resources/application.properties | 10 +++- backend/src/main/resources/localhost.p12 | Bin 0 -> 2416 bytes frontend/vue.config.js | 2 +- 5 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/config/HTTPSConfig.java create mode 100644 backend/src/main/resources/localhost.p12 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 0000000000000000000000000000000000000000..ca0fb6fa4ba39fa0d41c7f393218cc79bed91f23 GIT binary patch literal 2416 zcmY+Ec{CJ^8pdZcW^CEF(Nri)mLWvc=qnmDijwF<#x_}6?6Nl2#88y7g{%`9+gOV% zGq$mgZH5xri)ifB)j9Xx@7_P&^StMI-t+$Vdr$Xv{bn^uF2V^oy}9>i^!4Sd8ACtjE!?g>0gU$|5F{Z!nd!HKcpu|jDb zhdg}u*k2J=zC=89A@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1vUDiXNVFKZJpd%n4h;{6 z^9EJrN-kw|1Ua*_*Oz+rr-X5C_e06IrQk{%w_#2Hl#^=dWyDaS{RVQZLVZk_dgx8~wN z!B)+A=Br*yq<{#*L4D-93Q_G7q>Lf@b6UZYJ?sdr#7S|_`?VS?ZjcACb*}Z|8eLmZ z;7NlE<@>Wiqb+q`1^W88e^i65;|6bN(y7QaY zE$tE>2z0e=wL+S^M>dRfR+9Qy)_zv~(p9eh_c3(FaD9)c7%czD)AxPnN0$!~@86uu z>P5=i^tjhwA1rxf@*`~9k1V}XW=W6GK_DOkqn8anRrwP#*{juNK^kd$ZCt*nggX?O z0rZQ=+3?lSr}-X@uX)P-@eYm%Ow}UmovA?XVZI|}J)B3WSuLk6SSn$D`vnfQ*ScO6 zp*t`j;p7$DT_XzZ%Ot>Tq}p0MK9Pf1kWrb|G+DGYT;+%fT)Qp}vZ}I;6}YJW;r9_8 zQMU$Bv2spWz~EL+2}j6@t{?HP^xZozZ4wkmsDn$SXqxP1tN6Dh(>$UptBRkiH*S1g zNw#VzGyL+Y5kfQ)0|^rC=sxAsMTP`p@8{3OA@tnV<8TO#jm_G^@Mn3s>E`NLDAs zf7jaKf=fA%Z=I@~y23mYqVvWoXnYhuR;(^uq0o9WOS{6$<$RKRjpf_@foyIDBb6f| z{O>Kq(WpG=MjNE(^tTjpyM-DCb?m?G2p3ipMhXJl0rvn70Q&>QA8cL#Zz#)V2~sS03v)gw$^PTe)=^NL6TTT Xr+;??IW<6Fp_@ZmCkpAte~R>9@F9F8 literal 0 HcmV?d00001 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, }, }