From 31770de0f275a6789be3e1af705c35cddc6297cb Mon Sep 17 00:00:00 2001
From: nikyotensai <1246846408@qq.com>
Date: Sat, 4 Feb 2023 11:43:46 +0800
Subject: [PATCH 1/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0prod=E7=9A=84profile?=
=?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81=E5=89=8D=E5=90=8E=E7=AB=AF=E4=B8=80?=
=?UTF-8?q?=E8=B5=B7=E6=89=93=E5=8C=85?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
ruoyi-admin/pom.xml | 81 +++++++++++++++++++++++++++++++++++++++++----
1 file changed, 75 insertions(+), 6 deletions(-)
diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml
index 9a4cde8fbd..c0b309a82a 100644
--- a/ruoyi-admin/pom.xml
+++ b/ruoyi-admin/pom.xml
@@ -15,6 +15,11 @@
web服务入口
+
+ 1.12.1
+ ${project.parent.basedir}/ruoyi-ui
+
+
@@ -63,6 +68,70 @@
+
+
+ prod
+
+
+
+ com.github.eirslett
+ frontend-maven-plugin
+ ${frontend-maven-plugin.version}
+
+ ${ui.path}
+ v12.22.12
+
+
+
+ install node and npm
+
+ install-node-and-npm
+
+
+
+ npm install
+
+ npm
+
+
+ install --registry=https://registry.npmmirror.com
+
+
+
+ npm run build:prod
+
+ npm
+
+
+ run build:prod
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+
+ ${project.build.sourceEncoding}
+ ${project.build.directory}
+
+
+ ${basedir}/target/classes/public
+ ${ui.path}/dist
+
+
+ ${basedir}/target/classes
+ src/main/resources
+
+
+
+
+
+
+
+
+
+
@@ -80,15 +149,15 @@
-
- org.apache.maven.plugins
- maven-war-plugin
- 3.1.0
+
+ org.apache.maven.plugins
+ maven-war-plugin
+ 3.1.0
false
${project.artifactId}
-
-
+
+
${project.artifactId}
From 4d0683feaaf8fe43aeb429f291706002ea6c8861 Mon Sep 17 00:00:00 2001
From: nikyotensai <1246846408@qq.com>
Date: Sat, 4 Feb 2023 15:37:23 +0800
Subject: [PATCH 2/4] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=B5=84=E6=BA=90?=
=?UTF-8?q?=E8=AE=BF=E9=97=AE=E8=B7=AF=E5=BE=84=EF=BC=8C=E6=94=AF=E6=8C=81?=
=?UTF-8?q?=E5=8D=95=E5=BA=94=E7=94=A8=E9=83=A8=E7=BD=B2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/main/resources/application-prod.yml | 64 +++++++++++++++++++
ruoyi-admin/src/main/resources/logback.xml | 2 +-
.../com/ruoyi/common/config/RuoYiConfig.java | 35 ++++++++--
.../com/ruoyi/framework/config/MvcConfig.java | 22 +++++++
.../framework/config/ResourcesConfig.java | 38 +++++++++--
.../framework/config/SecurityConfig.java | 15 +++--
6 files changed, 160 insertions(+), 16 deletions(-)
create mode 100644 ruoyi-admin/src/main/resources/application-prod.yml
create mode 100644 ruoyi-framework/src/main/java/com/ruoyi/framework/config/MvcConfig.java
diff --git a/ruoyi-admin/src/main/resources/application-prod.yml b/ruoyi-admin/src/main/resources/application-prod.yml
new file mode 100644
index 0000000000..7bc25a5947
--- /dev/null
+++ b/ruoyi-admin/src/main/resources/application-prod.yml
@@ -0,0 +1,64 @@
+ruoyi:
+ pathPrefix: /prod-api
+ frontendPrefix:
+ - /index
+ - /system
+ - /monitor
+ - /tool
+# 数据源配置
+spring:
+ datasource:
+ type: com.alibaba.druid.pool.DruidDataSource
+ driverClassName: com.mysql.cj.jdbc.Driver
+ druid:
+ # 主库数据源
+ master:
+ url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
+ username: root
+ password: 123456
+ # 从库数据源
+ slave:
+ # 从数据源开关/默认关闭
+ enabled: false
+ url:
+ username:
+ password:
+ # 初始连接数
+ initialSize: 5
+ # 最小连接池数量
+ minIdle: 10
+ # 最大连接池数量
+ maxActive: 20
+ # 配置获取连接等待超时的时间
+ maxWait: 60000
+ # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
+ timeBetweenEvictionRunsMillis: 60000
+ # 配置一个连接在池中最小生存的时间,单位是毫秒
+ minEvictableIdleTimeMillis: 300000
+ # 配置一个连接在池中最大生存的时间,单位是毫秒
+ maxEvictableIdleTimeMillis: 900000
+ # 配置检测连接是否有效
+ validationQuery: SELECT 1 FROM DUAL
+ testWhileIdle: true
+ testOnBorrow: false
+ testOnReturn: false
+ webStatFilter:
+ enabled: true
+ statViewServlet:
+ enabled: true
+ # 设置白名单,不填则允许所有访问
+ allow:
+ url-pattern: /druid/*
+ # 控制台管理用户名和密码
+ login-username: ruoyi
+ login-password: 123456
+ filter:
+ stat:
+ enabled: true
+ # 慢SQL记录
+ log-slow-sql: true
+ slow-sql-millis: 1000
+ merge-sql: true
+ wall:
+ config:
+ multi-statement-allow: true
\ No newline at end of file
diff --git a/ruoyi-admin/src/main/resources/logback.xml b/ruoyi-admin/src/main/resources/logback.xml
index d69a572073..6a1db8259d 100644
--- a/ruoyi-admin/src/main/resources/logback.xml
+++ b/ruoyi-admin/src/main/resources/logback.xml
@@ -1,7 +1,7 @@
-
+
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/config/RuoYiConfig.java b/ruoyi-common/src/main/java/com/ruoyi/common/config/RuoYiConfig.java
index 84c0029db7..1d1211348d 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/config/RuoYiConfig.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/config/RuoYiConfig.java
@@ -1,8 +1,11 @@
package com.ruoyi.common.config;
+import com.ruoyi.common.utils.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
+import java.util.List;
+
/**
* 读取项目相关配置
*
@@ -32,9 +35,17 @@ public class RuoYiConfig
/** 验证码类型 */
private static String captchaType;
+ /**
+ * 后端接口前缀
+ */
+ private static String pathPrefix;
- public String getName()
- {
+ /**
+ * 前端前缀
+ */
+ private static List frontendPrefix;
+
+ public String getName() {
return name;
}
@@ -101,11 +112,27 @@ public void setCaptchaType(String captchaType) {
RuoYiConfig.captchaType = captchaType;
}
+
+ public static String getPathPrefix() {
+ return StringUtils.nvl(pathPrefix, "");
+ }
+
+ public void setPathPrefix(String pathPrefix) {
+ RuoYiConfig.pathPrefix = pathPrefix;
+ }
+
+ public static List getFrontendPrefix() {
+ return frontendPrefix;
+ }
+
+ public void setFrontendPrefix(List frontendPrefix) {
+ RuoYiConfig.frontendPrefix = frontendPrefix;
+ }
+
/**
* 获取导入上传路径
*/
- public static String getImportPath()
- {
+ public static String getImportPath() {
return getProfile() + "/import";
}
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MvcConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MvcConfig.java
new file mode 100644
index 0000000000..cf9cb506d2
--- /dev/null
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MvcConfig.java
@@ -0,0 +1,22 @@
+package com.ruoyi.framework.config;
+
+import com.ruoyi.common.config.RuoYiConfig;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+/**
+ * 通用配置
+ *
+ * @author ruoyi
+ */
+@Configuration
+public class MvcConfig implements WebMvcConfigurer {
+
+ @Override
+ public void configurePathMatch(PathMatchConfigurer configurer) {
+ configurer.addPathPrefix(RuoYiConfig.getPathPrefix(), c -> c.isAnnotationPresent(RestController.class));
+ }
+
+}
\ No newline at end of file
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java
index 4e067a7b16..3498ea5145 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java
@@ -1,6 +1,10 @@
package com.ruoyi.framework.config;
-import java.util.concurrent.TimeUnit;
+import com.ruoyi.common.config.RuoYiConfig;
+import com.ruoyi.common.constant.Constants;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.framework.interceptor.RepeatSubmitInterceptor;
+import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -8,12 +12,14 @@
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
+import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
-import com.ruoyi.common.config.RuoYiConfig;
-import com.ruoyi.common.constant.Constants;
-import com.ruoyi.framework.interceptor.RepeatSubmitInterceptor;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.concurrent.TimeUnit;
/**
* 通用配置
@@ -46,6 +52,30 @@ public void addResourceHandlers(ResourceHandlerRegistry registry)
public void addInterceptors(InterceptorRegistry registry)
{
registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns("/**");
+ addUiInterceptor(registry);
+ }
+
+
+ private void addUiInterceptor(InterceptorRegistry registry) {
+ if (StringUtils.isEmpty(RuoYiConfig.getPathPrefix()) || CollectionUtils.isEmpty(RuoYiConfig.getFrontendPrefix())) {
+ return;
+ }
+ registry.addInterceptor(new HandlerInterceptor() {
+ @Override
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+ String servletPath = request.getServletPath();
+ if (servletPath.equals("/")) {
+ request.getRequestDispatcher("/index.html").forward(request, response);
+ }
+ for (String prefix : RuoYiConfig.getFrontendPrefix()) {
+ if (request.getServletPath().startsWith(prefix) && !request.getServletPath().equals("/index.html")) {
+ request.getRequestDispatcher("/index.html").forward(request, response);
+ break;
+ }
+ }
+ return true;
+ }
+ }).addPathPatterns("/**");
}
/**
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java
index bdb7199fe9..b008f4eba3 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java
@@ -1,5 +1,10 @@
package com.ruoyi.framework.config;
+import com.ruoyi.common.config.RuoYiConfig;
+import com.ruoyi.framework.config.properties.PermitAllUrlProperties;
+import com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter;
+import com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl;
+import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpMethod;
@@ -15,10 +20,6 @@
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.logout.LogoutFilter;
import org.springframework.web.filter.CorsFilter;
-import com.ruoyi.framework.config.properties.PermitAllUrlProperties;
-import com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter;
-import com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl;
-import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl;
/**
* spring security配置
@@ -111,16 +112,16 @@ protected void configure(HttpSecurity httpSecurity) throws Exception
// 过滤请求
.authorizeRequests()
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
- .antMatchers("/login", "/register", "/captchaImage").permitAll()
+ .antMatchers(RuoYiConfig.getPathPrefix()+"/login", RuoYiConfig.getPathPrefix()+"/register", RuoYiConfig.getPathPrefix()+"/captchaImage").permitAll()
// 静态资源,可匿名访问
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
// 除上面外的所有请求全部需要鉴权认证
- .anyRequest().authenticated()
+ .antMatchers(RuoYiConfig.getPathPrefix()+"/**").authenticated()
.and()
.headers().frameOptions().disable();
// 添加Logout filter
- httpSecurity.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler);
+ httpSecurity.logout().logoutUrl(RuoYiConfig.getPathPrefix()+"/logout").logoutSuccessHandler(logoutSuccessHandler);
// 添加JWT filter
httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
// 添加CORS filter
From c46d4f0dd1c773809a23822eeb8f7635eda5651e Mon Sep 17 00:00:00 2001
From: nikyotensai <1246846408@qq.com>
Date: Sat, 4 Feb 2023 17:24:43 +0800
Subject: [PATCH 3/4] add Dockerfile
---
ruoyi-admin/Dockerfile | 6 ++++++
1 file changed, 6 insertions(+)
create mode 100644 ruoyi-admin/Dockerfile
diff --git a/ruoyi-admin/Dockerfile b/ruoyi-admin/Dockerfile
new file mode 100644
index 0000000000..f486b984ce
--- /dev/null
+++ b/ruoyi-admin/Dockerfile
@@ -0,0 +1,6 @@
+FROM openjdk:8-jdk
+RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
+
+ADD target/ruoyi-admin.jar /ruoyi-admin.jar
+EXPOSE 8080
+ENTRYPOINT ["java","-XX:+UseContainerSupport","-XX:InitialRAMPercentage=50.0","-XX:MaxRAMPercentage=50.0","-Duser.timezone=Asia/Shanghai","-Dspring.profiles.active=dev","-jar","/ruoyi-admin.jar"]
\ No newline at end of file
From fe0b1a9e5207b2410159dddaa56dd3044f22887e Mon Sep 17 00:00:00 2001
From: nikyotensai <1246846408@qq.com>
Date: Sat, 4 Feb 2023 18:10:33 +0800
Subject: [PATCH 4/4] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=85=8D=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
ruoyi-admin/Dockerfile | 2 +-
ruoyi-admin/src/main/resources/application-prod.yml | 7 ++++---
.../main/java/com/ruoyi/framework/config/MvcConfig.java | 5 +++--
3 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/ruoyi-admin/Dockerfile b/ruoyi-admin/Dockerfile
index f486b984ce..af0955532b 100644
--- a/ruoyi-admin/Dockerfile
+++ b/ruoyi-admin/Dockerfile
@@ -3,4 +3,4 @@ RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ADD target/ruoyi-admin.jar /ruoyi-admin.jar
EXPOSE 8080
-ENTRYPOINT ["java","-XX:+UseContainerSupport","-XX:InitialRAMPercentage=50.0","-XX:MaxRAMPercentage=50.0","-Duser.timezone=Asia/Shanghai","-Dspring.profiles.active=dev","-jar","/ruoyi-admin.jar"]
\ No newline at end of file
+ENTRYPOINT ["java","-XX:+UseContainerSupport","-XX:InitialRAMPercentage=50.0","-XX:MaxRAMPercentage=50.0","-Duser.timezone=Asia/Shanghai","-jar","/ruoyi-admin.jar"]
\ No newline at end of file
diff --git a/ruoyi-admin/src/main/resources/application-prod.yml b/ruoyi-admin/src/main/resources/application-prod.yml
index 7bc25a5947..d450caf901 100644
--- a/ruoyi-admin/src/main/resources/application-prod.yml
+++ b/ruoyi-admin/src/main/resources/application-prod.yml
@@ -2,6 +2,7 @@ ruoyi:
pathPrefix: /prod-api
frontendPrefix:
- /index
+ - /login
- /system
- /monitor
- /tool
@@ -13,9 +14,9 @@ spring:
druid:
# 主库数据源
master:
- url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
- username: root
- password: 123456
+ url: jdbc:mysql://${mysql.host:localhost:3306}/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
+ username: ${mysql.username:root}
+ password: ${mysql.password:123456}
# 从库数据源
slave:
# 从数据源开关/默认关闭
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MvcConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MvcConfig.java
index cf9cb506d2..e3fad71f42 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MvcConfig.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MvcConfig.java
@@ -7,9 +7,10 @@
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
- * 通用配置
+ * mvc配置
*
- * @author ruoyi
+ * @author nikyotensai
+ * @since 2023-02-04
*/
@Configuration
public class MvcConfig implements WebMvcConfigurer {