refactor: 开启http2,支持http和https端口
This commit is contained in:
parent
71a2835dcf
commit
83ef71276a
|
@ -63,7 +63,7 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jetty</artifactId>
|
||||
<artifactId>spring-boot-starter-undertow</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
Binary file not shown.
|
@ -13,7 +13,7 @@ module.exports = {
|
|||
//1.8需求:增加分享功能,不登陆即可看到文档页面。所以代理设置增加了(?!/document)文档页面的相关信息
|
||||
// ['^(?!/login)']: {
|
||||
['^((?!/login)(?!/document))']: {
|
||||
target: 'http://localhost:8081',
|
||||
target: 'https://localhost:8443',
|
||||
ws: true,
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue