Skip to content

Commit 68760e3

Browse files
xiaorongnieipcjsTranscodeGroupDevelopercli
authored
feat(cors): 配置跨域策略 (#47)
* feat(cors): 默认禁用跨域 默认不启用跨域验证 * wip: 默认允许公网域名和IP的任意端口访问 * feat(cors):增加设备厂家,设备类型,设备型号初始化数据表 * nginx * wip: 让Spring识别nginx添加的X-Forwarded-*头 * wip: 整理配置 --------- Co-authored-by: ipcjs.mac4 <gipcjs@gmail.com> Co-authored-by: TranscodeGroupDeveloper <transcodegroupdeveloper@gmail.com> Co-authored-by: cli <cli@debian>
1 parent 7c108dc commit 68760e3

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

maintain/compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ services:
4242

4343
# 网关指令
4444
- spring_my_gateway_jtt808_url=http://${JTT808_HOST:-jtt808}:${JTT808_PORT_HTTP:-9012}
45+
# 让Spring识别nginx添加的X-Forwarded-*头, 参考: https://docs.spring.io/spring-boot/how-to/webserver.html#howto.webserver.use-behind-a-proxy-server
46+
- SERVER_FORWARD_HEADERS_STRATEGY=native
4547

4648
# 短信服务
4749
# - tencent_sms_secret_id=AKID74lBKCoAF2YomUv60e06vTkkSt3wYtxk
@@ -56,7 +58,7 @@ services:
5658
- spring_my_push_group_secret=63b4ff15d550ba1675b1dceb
5759

5860
# 跨域 逗号分割
59-
- spring_my_cors_origin-patterns=https://*.tgtrack.com,https://*.tripsdd.com,https://tripsdd.com
61+
- spring_my_cors_origin-patterns=*://${TRACK_HOSTNAME}:[*],*://${SERVER_IP_PUBLIC}:[*]
6062

6163
# Mail-预设了bus的邮箱
6264
- spring_mail_host=${MAIL_HOST:-smtp.transcodegroup.com}

mysql8/initdb/02-maintain-init-data.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,27 @@ INSERT INTO `system_dictionary` VALUES (47, '47', '轨迹完整率低', '轨迹
200200
INSERT INTO `system_dictionary` VALUES (48, '48', '漂移', '漂移', 'drift', 'GPS กระโดด', 'drift', 'Deriva', 'Deriva', 'Fault-Type', NULL, NULL, 0, 0, '2022-05-09 03:27:18', '2025-10-09 04:31:10');
201201
INSERT INTO `system_dictionary` VALUES (49, '49', '不读司机卡', '不读司机卡', 'Does not read driver card', 'เครื่องรูดบัตร', 'Tidak membaca kartu pengemudi', 'No lee la tarjeta del conductor', 'Não lê o cartão do motorista', 'Fault-Type', NULL, NULL, 0, 0, '2022-05-09 03:27:18', '2025-10-09 04:31:10');
202202

203+
204+
-- ----------------------------
205+
-- Records of device_category
206+
-- ----------------------------
207+
208+
INSERT INTO `maintain`.`device_category` VALUES (1, '1d3b089c74ca496b8c17cfa77e13a65a', '视频终端', '视频终端', 'MDVR', 'MDVR', 'MDVR', 'MDVR', 'MDVR', '', 200, 0, '2026-01-21 07:14:15', '2026-01-21 07:14:15');
209+
INSERT INTO `maintain`.`device_category` VALUES (2, 'ed4d3d9b5eda4dfe9a6cdb1327ec1690', 'GPS Tracker', 'GPS Tracker', 'GPS Tracker', 'GPS Tracker', 'GPS Tracker', 'GPS Tracker', 'GPS Tracker', '', 100, 0, '2026-01-21 07:58:47', '2026-01-21 07:58:47');
210+
211+
-- ----------------------------
212+
-- Records of device_manufacturer
213+
-- ----------------------------
214+
215+
INSERT INTO `maintain`.`device_manufacturer` VALUES (1, '43a610ca929d45dea574b1122e313e2b', 'TGC', '100010001', NULL, 0, '2026-01-21 07:13:43', '2026-01-21 07:13:43');
216+
217+
-- ----------------------------
218+
-- Records of device_product
219+
-- ----------------------------
220+
221+
INSERT INTO `maintain`.`device_product` VALUES (1, '7de049b26def4364a9f3dc3bc60cf029', 'TCG-MDVR', 'TCG-MDVR', '1d3b089c74ca496b8c17cfa77e13a65a', '[\"808-2011\",\"808-2013\",\"808-2016\",\"808-2019\",\"1078-2016\",\"safety-jiangsu\",\"tl\"]', '', 2, 4095, '43a610ca929d45dea574b1122e313e2b', 'TGC', NULL, '', 0, NULL, NULL, 0, '', '[\"TCG-MDVR\"]', 0, '2026-01-21 07:15:23', '2026-01-21 07:16:39');
222+
INSERT INTO `maintain`.`device_product` VALUES (2, 'bf56842a3d80445c96d705e91320a92a', 'GPS Tracker', 'GPS Tracker', 'ed4d3d9b5eda4dfe9a6cdb1327ec1690', '[\"808-2011\",\"808-2013\",\"808-2019\",\"tg\"]', '', 0, 288, '43a610ca929d45dea574b1122e313e2b', 'TGC', NULL, '', 0, NULL, NULL, 0, '', NULL, 0, '2026-01-21 08:02:53', '2026-01-21 08:02:53');
223+
224+
225+
203226
SET FOREIGN_KEY_CHECKS = 1;

nginx/conf/conf.d/track.conf.template

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,20 @@ server {
7272

7373
location /api/ {
7474
proxy_pass http://track_api_server;
75-
proxy_set_header X-Real-IP $remote_addr;
7675
proxy_set_header Host $http_host;
76+
proxy_set_header X-Real-IP $remote_addr;
7777
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
78+
proxy_set_header X-Forwarded-Proto $scheme;
7879
proxy_set_header Upgrade $http_upgrade;
7980
proxy_set_header Connection $connection_upgrade;
8081
}
8182

8283
location ~ ^/(pass|file|datamotor|video|health)/ {
8384
proxy_pass http://track_api_server;
84-
proxy_set_header X-Real-IP $remote_addr;
8585
proxy_set_header Host $http_host;
86+
proxy_set_header X-Real-IP $remote_addr;
8687
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
88+
proxy_set_header X-Forwarded-Proto $scheme;
8789
proxy_set_header Upgrade $http_upgrade;
8890
proxy_set_header Connection $connection_upgrade;
8991
}

0 commit comments

Comments
 (0)