|
|
@@ -5,29 +5,35 @@ spring:
|
|
5
|
5
|
name: gateWay-server
|
|
6
|
6
|
profiles:
|
|
7
|
7
|
active: dev
|
|
8
|
|
-# cloud: # <--- 添加或合并到现有的 spring.cloud 块下
|
|
|
8
|
+# cloud:
|
|
9
|
9
|
# gateway:
|
|
10
|
|
-# globalcors: # <--- 全局 CORS 配置
|
|
|
10
|
+# globalcors: # 全局 CORS 配置
|
|
11
|
11
|
# cors-configurations:
|
|
12
|
|
-# '[/**]': # <--- 对所有路径 (/**) 应用此 CORS 配置
|
|
13
|
|
-# # -- 重要:修改为你本地运行的前端地址和端口 --
|
|
14
|
|
-# # allowedOrigins: "http://localhost:8080" # 如果只允许单个精确源
|
|
15
|
|
-# allowedOriginPatterns: # 更推荐,允许 localhost 的任意端口
|
|
16
|
|
-# - "*"
|
|
17
|
|
-# # --↑↑↑ 根据你前端实际情况修改 ↑↑↑--
|
|
|
12
|
+# '[/**]': # 对所有路径应用此 CORS 配置
|
|
|
13
|
+# # --- 修改这里 ---
|
|
|
14
|
+# # 将 "*" 改回具体的开发环境地址模式
|
|
|
15
|
+# allowedOriginPatterns:
|
|
|
16
|
+# - "http://localhost:*" # 允许来自 http://localhost 的任意端口
|
|
|
17
|
+# - "http://127.0.0.1:*" # 允许来自 http://127.0.0.1 的任意端口
|
|
|
18
|
+# # --- ↑↑↑ 关键修改 ↑↑↑ ---
|
|
|
19
|
+# # 如果你的前端运行在特定端口,例如 8080,也可以用更精确的 (但上面的模式更灵活):
|
|
|
20
|
+# # allowedOrigins: "http://localhost:8080" # 注意这里用 allowedOrigins
|
|
18
|
21
|
#
|
|
19
|
|
-# allowedMethods: # 允许的 HTTP 方法
|
|
|
22
|
+# allowedMethods:
|
|
20
|
23
|
# - "GET"
|
|
21
|
24
|
# - "POST"
|
|
22
|
25
|
# - "PUT"
|
|
23
|
26
|
# - "DELETE"
|
|
24
|
|
-# - "OPTIONS" # OPTIONS 很重要,用于预检请求
|
|
25
|
|
-# allowedHeaders: "*" # 允许所有请求头
|
|
26
|
|
-# allowCredentials: true # 允许发送 Cookie 等凭证
|
|
27
|
|
-# maxAge: 360000 # 预检请求 (OPTIONS) 的缓存时间 (毫秒)
|
|
|
27
|
+# - "OPTIONS"
|
|
|
28
|
+# allowedHeaders: "*"
|
|
|
29
|
+# allowCredentials: true # 保留 true,因为你需要凭证
|
|
|
30
|
+# maxAge: 360000
|
|
28
|
31
|
#
|
|
29
|
|
-## 如果你的 Gateway 也使用了 Spring Security, 你可能还需要在Security配置中处理CORS
|
|
30
|
|
-## (见上一个回答中的 Spring Security 配置示例),并且要放行 OPTIONS 请求。
|
|
|
32
|
+## --- 仍然重要的提醒 ---
|
|
|
33
|
+## 检查是否使用了 Spring Security。如果使用了,强烈建议将 CORS 配置
|
|
|
34
|
+## 统一放在 Spring Security 的配置中,并移除或注释掉这里的 globalcors 部分,
|
|
|
35
|
+## 以避免配置冲突。
|
|
|
36
|
+## ---
|
|
31
|
37
|
|
|
32
|
38
|
logging:
|
|
33
|
39
|
config: classpath:log4j2.xml
|