From 1819c9e111214b2acfdebeb2b115719a32e68c97 Mon Sep 17 00:00:00 2001 From: fanfpy Date: Tue, 15 Jul 2025 18:55:50 +0800 Subject: [PATCH] =?UTF-8?q?refactor(consul):=20=E5=B0=86=E4=B8=BB=E6=9C=BA?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E8=A7=84=E5=88=99=E6=94=B9=E4=B8=BA=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E5=89=8D=E7=BC=80=E5=B9=B6=E6=B7=BB=E5=8A=A0=E4=B8=AD?= =?UTF-8?q?=E9=97=B4=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改所有服务的路由规则,从基于主机名改为基于路径前缀 为每个服务添加strip前缀中间件以正确处理API请求 --- consul/config/dev/data-service.json | 10 ++++++---- consul/config/dev/emotion-service.json | 6 ++++-- consul/config/dev/frontend.json | 2 +- consul/config/dev/quant-service.json | 6 ++++-- consul/config/dev/recommend-service.json | 6 ++++-- consul/config/dev/user-service.json | 6 ++++-- 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/consul/config/dev/data-service.json b/consul/config/dev/data-service.json index 149ae67..69d5d4a 100644 --- a/consul/config/dev/data-service.json +++ b/consul/config/dev/data-service.json @@ -8,10 +8,12 @@ }, "id": "data-service-1", "tags": [ - "traefik.enable=true", - "traefik.http.routers.data-service.rule=Host(\"data.aristockai.com\")", - "traefik.http.routers.data-service.entrypoints=web" - ], + "traefik.enable=true", + "traefik.http.routers.data-service.rule=PathPrefix(`/api/data`) || PathPrefix(`/api/public`)", + "traefik.http.routers.data-service.entrypoints=web", + "traefik.http.middlewares.data-service-stripprefix.stripprefix.prefixes=/api/data,/api/public", + "traefik.http.routers.data-service.middlewares=data-service-stripprefix@consulcatalog" + ], "name": "data-service", "port": 8000 } diff --git a/consul/config/dev/emotion-service.json b/consul/config/dev/emotion-service.json index 0919352..1371776 100644 --- a/consul/config/dev/emotion-service.json +++ b/consul/config/dev/emotion-service.json @@ -9,8 +9,10 @@ "id": "emotion-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.emotion-service.rule=Host(\"emotion.aristockai.com\")", - "traefik.http.routers.emotion-service.entrypoints=web" + "traefik.http.routers.emotion-service.rule=PathPrefix(`/api/emotion`) || PathPrefix(`/api/sentiment`)", + "traefik.http.routers.emotion-service.entrypoints=web", + "traefik.http.middlewares.emotion-service-stripprefix.stripprefix.prefixes=/api/emotion,/api/sentiment", + "traefik.http.routers.emotion-service.middlewares=emotion-service-stripprefix@consulcatalog" ], "name": "emotion-service", "port": 8002 diff --git a/consul/config/dev/frontend.json b/consul/config/dev/frontend.json index e191e41..03e5b30 100644 --- a/consul/config/dev/frontend.json +++ b/consul/config/dev/frontend.json @@ -9,7 +9,7 @@ "id": "frontend-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.frontend.rule=Host(\"aristockai.com\") || Host(\"www.aristockai.com\")", + "traefik.http.routers.frontend.rule=PathPrefix(`/`) || PathPrefix(`/index.html`) || PathPrefix(`/static`)", "traefik.http.routers.frontend.entrypoints=web" ], "name": "frontend", diff --git a/consul/config/dev/quant-service.json b/consul/config/dev/quant-service.json index ef7a1ea..5c8b8ef 100644 --- a/consul/config/dev/quant-service.json +++ b/consul/config/dev/quant-service.json @@ -9,8 +9,10 @@ "id": "quant-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.quant-service.rule=Host(\"quant.aristockai.com\")", - "traefik.http.routers.quant-service.entrypoints=web" + "traefik.http.routers.quant-service.rule=PathPrefix(`/api/quant`) || PathPrefix(`/api/strategy`)", + "traefik.http.routers.quant-service.entrypoints=web", + "traefik.http.middlewares.quant-service-stripprefix.stripprefix.prefixes=/api/quant,/api/strategy", + "traefik.http.routers.quant-service.middlewares=quant-service-stripprefix@consulcatalog" ], "name": "quant-service", "port": 8001 diff --git a/consul/config/dev/recommend-service.json b/consul/config/dev/recommend-service.json index 61dfe90..a016ad5 100644 --- a/consul/config/dev/recommend-service.json +++ b/consul/config/dev/recommend-service.json @@ -9,8 +9,10 @@ "id": "recommend-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.recommend-service.rule=Host(\"recommend.aristockai.com\")", - "traefik.http.routers.recommend-service.entrypoints=web" + "traefik.http.routers.recommend-service.rule=PathPrefix(`/api/recommend`) || PathPrefix(`/api/suggest`)", + "traefik.http.routers.recommend-service.entrypoints=web", + "traefik.http.middlewares.recommend-service-stripprefix.stripprefix.prefixes=/api/recommend,/api/suggest", + "traefik.http.routers.recommend-service.middlewares=recommend-service-stripprefix@consulcatalog" ], "name": "recommend-service", "port": 8003 diff --git a/consul/config/dev/user-service.json b/consul/config/dev/user-service.json index 0384d27..3231f67 100644 --- a/consul/config/dev/user-service.json +++ b/consul/config/dev/user-service.json @@ -9,8 +9,10 @@ "id": "user-service-1", "tags": [ "traefik.enable=true", - "traefik.http.routers.user-service.rule=Host(\"user.aristockai.com\")", - "traefik.http.routers.user-service.entrypoints=web" + "traefik.http.routers.user-service.rule=PathPrefix(`/api/user`) || PathPrefix(`/api/auth`)", + "traefik.http.routers.user-service.entrypoints=web", + "traefik.http.middlewares.user-service-stripprefix.stripprefix.prefixes=/api/user,/api/auth", + "traefik.http.routers.user-service.middlewares=user-service-stripprefix@consulcatalog" ], "name": "user-service", "port": 8004