From da3f8455916f7063f0b09225c28e2d03e3875882 Mon Sep 17 00:00:00 2001 From: fanfpy Date: Tue, 1 Jul 2025 16:38:55 +0800 Subject: [PATCH] =?UTF-8?q?refactor(consul):=20=E7=BB=9F=E4=B8=80Traefik?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E8=A7=84=E5=88=99=E6=A0=BC=E5=BC=8F=E5=B9=B6?= =?UTF-8?q?=E7=AE=80=E5=8C=96whoami=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将所有服务的Traefik路由规则从点分隔符改为下划线格式 - 简化whoami服务配置,移除中间件并更新路由规则 - 统一所有服务的配置格式以提高可维护性 --- consul/config/data-service.json | 2 +- consul/config/emotion-service.json | 2 +- consul/config/frontend.json | 2 +- consul/config/quant-service.json | 2 +- consul/config/recommend-service.json | 2 +- consul/config/user-service.json | 2 +- consul/config/whoami.json | 25 +++++++++++-------------- 7 files changed, 17 insertions(+), 20 deletions(-) diff --git a/consul/config/data-service.json b/consul/config/data-service.json index 52ba919..437bd59 100644 --- a/consul/config/data-service.json +++ b/consul/config/data-service.json @@ -9,7 +9,7 @@ "id": "data-service-1", "meta": { "traefik_enable": "true", - "traefik.http.routers.data-service.rule": "PathPrefix('/api/data')" + "traefik_http_routers_data_service_rule": "PathPrefix('/api/data')" }, "name": "data-service", "port": 8000 diff --git a/consul/config/emotion-service.json b/consul/config/emotion-service.json index 1818fb5..5d91c51 100644 --- a/consul/config/emotion-service.json +++ b/consul/config/emotion-service.json @@ -9,7 +9,7 @@ "id": "emotion-service-1", "meta": { "traefik_enable": "true", - "traefik.http.routers.emotion-service.rule": "PathPrefix('/api/emotion')" + "traefik_http_routers_emotion_service_rule": "PathPrefix('/api/emotion')" }, "name": "emotion-service", "port": 8002 diff --git a/consul/config/frontend.json b/consul/config/frontend.json index 93efea8..a2df057 100644 --- a/consul/config/frontend.json +++ b/consul/config/frontend.json @@ -9,7 +9,7 @@ "id": "frontend-1", "meta": { "traefik_enable": "true", - "traefik.http.routers.frontend.rule": "PathPrefix('/')" + "traefik_http_routers_frontend_rule": "PathPrefix('/')" }, "name": "frontend", "port": 80 diff --git a/consul/config/quant-service.json b/consul/config/quant-service.json index fe78f67..88b2e83 100644 --- a/consul/config/quant-service.json +++ b/consul/config/quant-service.json @@ -9,7 +9,7 @@ "id": "quant-service-1", "meta": { "traefik_enable": "true", - "traefik.http.routers.quant-service.rule": "PathPrefix('/api/quant')" + "traefik_http_routers_quant_service_rule": "PathPrefix('/api/quant')" }, "name": "quant-service", "port": 8001 diff --git a/consul/config/recommend-service.json b/consul/config/recommend-service.json index 923320d..9818eda 100644 --- a/consul/config/recommend-service.json +++ b/consul/config/recommend-service.json @@ -9,7 +9,7 @@ "id": "recommend-service-1", "meta": { "traefik_enable": "true", - "raefik.http.routers.quant-service.rule": "PathPrefix(`/api/recommend`)" + "traefik_http_routers_recommend_service_rule": "PathPrefix('/api/recommend')" }, "name": "recommend-service", "port": 8003 diff --git a/consul/config/user-service.json b/consul/config/user-service.json index 00cbcc3..a94219e 100644 --- a/consul/config/user-service.json +++ b/consul/config/user-service.json @@ -9,7 +9,7 @@ "id": "user-service-1", "meta": { "traefik_enable": "true", - "raefik.http.routers.quant-service.rule": "PathPrefix(`/api/user`)" + "traefik_http_routers_user_service_rule": "PathPrefix('/api/user')" }, "name": "user-service", "port": 8004 diff --git a/consul/config/whoami.json b/consul/config/whoami.json index 2fb6d29..6d47134 100644 --- a/consul/config/whoami.json +++ b/consul/config/whoami.json @@ -1,23 +1,20 @@ { "service": { "name": "whoami", - "address": "whoami", - "port": 80, "tags": [ "traefik.enable=true", - "traefik.http.routers.whoami.rule=Host(`whoami.localhost`)", "traefik.http.routers.whoami.entrypoints=web", - "traefik.http.routers.whoami.middlewares=whoami-prefix" + "traefik.http.routers.whoami.rule=Path(`/whoami`)", + "traefik.http.services.whoami.loadbalancer.server.port=80" ], - "check": { - "http": "http://whoami:80/", - "interval": "10s" - } - }, - "middleware": { - "name": "whoami-prefix", - "pathPrefixStrip": { - "prefixes": ["/whoami"] - } + "address": "whoami", + "port": 80, + "checks": [ + { + "http": "http://whoami:80/", + "interval": "10s", + "timeout": "2s" + } + ] } }