Procházet zdrojové kódy

兼容 app 跨域支持

chenxiaoxiang před 9 měsíci
rodič
revize
0666aa7fc9

+ 10 - 1
docker/docker-compose.yml

@@ -99,4 +99,13 @@ services:
99 99
       context: ./web
100 100
       dockerfile: Dockerfile
101 101
     ports:
102
-      - "38081:80"
102
+      - "38081:80"
103
+
104
+
105
+  airport-app:
106
+    container_name: airport-app
107
+    build:
108
+      context: ./airport-app
109
+      dockerfile: Dockerfile
110
+    ports:
111
+      - "38084:9090"

+ 8 - 0
docker/run.sh

@@ -26,6 +26,7 @@ usage() {
26 26
     echo "  monitor   - 监控中心"
27 27
     echo "  exam   - 考试服务"
28 28
     echo "  airportWeb   - 管理前端"
29
+    echo "  app   - 移动端"
29 30
     echo -e "\n${YELLOW}管理命令:${NC}"
30 31
     echo "  stopAll   - 停止所有服务"
31 32
     echo "  rmAll     - 删除所有容器"
@@ -77,6 +78,11 @@ airportWeb() {
77 78
     restart_service "airport-web" "$1" "管理前端"
78 79
 }
79 80
 
81
+# 移动端
82
+app() {
83
+    restart_service "airport-app" "$1" "移动端"
84
+}
85
+
80 86
 # 核心重启逻辑
81 87
 restart_service() {
82 88
     local service=$1
@@ -121,6 +127,7 @@ restart() {
121 127
         "monitor") monitor "$2" ;;
122 128
         "exam") exam "$2" ;;
123 129
         "airportWeb") airportWeb "$2" ;;
130
+        "app") app "$2" ;;
124 131
         *) echo -e "${RED}未知模块: $1${NC}"; usage ;;
125 132
     esac
126 133
 }
@@ -136,6 +143,7 @@ case "$1" in
136 143
     "exam") exam "$2" ;;
137 144
     "monitor") monitor "$2" ;;
138 145
     "airportWeb") airportWeb "$2" ;;
146
+    "app") app "$2" ;;
139 147
     "stopAll") stopAll ;;
140 148
     "rmAll") rmAll ;;
141 149
     "restart") restart "$2" "$3" ;;

+ 57 - 0
ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/CorsConfig.java

@@ -0,0 +1,57 @@
1
+package com.ruoyi.gateway.config;
2
+
3
+import org.springframework.context.annotation.Bean;
4
+import org.springframework.context.annotation.Configuration;
5
+import org.springframework.http.HttpHeaders;
6
+import org.springframework.http.HttpMethod;
7
+import org.springframework.http.HttpStatus;
8
+import org.springframework.http.server.reactive.ServerHttpRequest;
9
+import org.springframework.http.server.reactive.ServerHttpResponse;
10
+import org.springframework.web.cors.reactive.CorsUtils;
11
+import org.springframework.web.server.ServerWebExchange;
12
+import org.springframework.web.server.WebFilter;
13
+import org.springframework.web.server.WebFilterChain;
14
+import reactor.core.publisher.Mono;
15
+
16
+/**
17
+ * 跨域配置
18
+ *
19
+ * @author ruoyi
20
+ */
21
+@Configuration
22
+public class CorsConfig
23
+{
24
+    /**
25
+     * 这里为支持的请求头,如果有自定义的header字段请自己添加
26
+     */
27
+    private static final String ALLOWED_HEADERS = "X-Requested-With, Content-Type, Authorization, credential, X-XSRF-TOKEN, token, Admin-Token, App-Token";
28
+    private static final String ALLOWED_METHODS = "GET,POST,PUT,DELETE,OPTIONS,HEAD";
29
+    private static final String ALLOWED_ORIGIN = "*";
30
+    private static final String ALLOWED_EXPOSE = "*";
31
+    private static final String MAX_AGE = "18000L";
32
+
33
+    @Bean
34
+    public WebFilter corsFilter()
35
+    {
36
+        return (ServerWebExchange ctx, WebFilterChain chain) -> {
37
+            ServerHttpRequest request = ctx.getRequest();
38
+            if (CorsUtils.isCorsRequest(request))
39
+            {
40
+                ServerHttpResponse response = ctx.getResponse();
41
+                HttpHeaders headers = response.getHeaders();
42
+                headers.add("Access-Control-Allow-Headers", ALLOWED_HEADERS);
43
+                headers.add("Access-Control-Allow-Methods", ALLOWED_METHODS);
44
+                headers.add("Access-Control-Allow-Origin", ALLOWED_ORIGIN);
45
+                headers.add("Access-Control-Expose-Headers", ALLOWED_EXPOSE);
46
+                headers.add("Access-Control-Max-Age", MAX_AGE);
47
+                headers.add("Access-Control-Allow-Credentials", "true");
48
+                if (request.getMethod() == HttpMethod.OPTIONS)
49
+                {
50
+                    response.setStatusCode(HttpStatus.OK);
51
+                    return Mono.empty();
52
+                }
53
+            }
54
+            return chain.filter(ctx);
55
+        };
56
+    }
57
+}