refactor: 开启http2,支持http和https端口

This commit is contained in:
Captain.B 2021-10-12 13:42:46 +08:00 committed by 刘瑞斌
parent 71a2835dcf
commit 83ef71276a
5 changed files with 63 additions and 3 deletions

View File

@ -63,7 +63,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId> <artifactId>spring-boot-starter-undertow</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>

View File

@ -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;
}
}

View File

@ -1,6 +1,14 @@
spring.application.name=metersphere 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 # Hikari
spring.datasource.type=com.zaxxer.hikari.HikariDataSource spring.datasource.type=com.zaxxer.hikari.HikariDataSource

Binary file not shown.

View File

@ -13,7 +13,7 @@ module.exports = {
//1.8需求:增加分享功能,不登陆即可看到文档页面。所以代理设置增加了(?!/document)文档页面的相关信息 //1.8需求:增加分享功能,不登陆即可看到文档页面。所以代理设置增加了(?!/document)文档页面的相关信息
// ['^(?!/login)']: { // ['^(?!/login)']: {
['^((?!/login)(?!/document))']: { ['^((?!/login)(?!/document))']: {
target: 'http://localhost:8081', target: 'https://localhost:8443',
ws: true, ws: true,
}, },
} }