iconsulting/kong/kong.yml

245 lines
7.0 KiB
YAML

#===============================================================================
# Kong API Gateway 声明式配置
#
# 此文件定义所有服务、路由和插件配置
# 可用于 DB-less 模式或作为配置参考文档
#
# 服务架构:
# - user-service: 用户认证和管理 (3001)
# - payment-service: 支付处理 (3002)
# - knowledge-service: 知识库服务 (3003)
# - conversation-service: 对话服务 (3004)
# - evolution-service: 进化服务 (3005)
# - file-service: 文件管理服务 (3006)
#
#===============================================================================
_format_version: "2.1"
_transform: true
#===============================================================================
# 服务和路由定义
#===============================================================================
services:
#-----------------------------------------------------------------------------
# User Service - 用户认证和管理
#-----------------------------------------------------------------------------
- name: user-service
url: http://user-service:3001
connect_timeout: 60000
write_timeout: 60000
read_timeout: 60000
retries: 3
routes:
- name: user-routes
paths:
- /api/v1/users
- /api/v1/auth
strip_path: false
preserve_host: true
methods:
- GET
- POST
- PUT
- PATCH
- DELETE
- OPTIONS
#-----------------------------------------------------------------------------
# Payment Service - 支付处理
#-----------------------------------------------------------------------------
- name: payment-service
url: http://payment-service:3002
connect_timeout: 60000
write_timeout: 60000
read_timeout: 60000
retries: 3
routes:
- name: payment-routes
paths:
- /api/v1/payments
- /api/v1/orders
- /api/v1/subscriptions
strip_path: false
preserve_host: true
methods:
- GET
- POST
- PUT
- PATCH
- DELETE
- OPTIONS
#-----------------------------------------------------------------------------
# Knowledge Service - 知识库服务
#-----------------------------------------------------------------------------
- name: knowledge-service
url: http://knowledge-service:3003
connect_timeout: 60000
write_timeout: 60000
read_timeout: 60000
retries: 3
routes:
- name: knowledge-routes
paths:
- /api/v1/knowledge
- /api/v1/memory
strip_path: false
preserve_host: true
methods:
- GET
- POST
- PUT
- PATCH
- DELETE
- OPTIONS
#-----------------------------------------------------------------------------
# Conversation Service - 对话服务
# 注意: 需要更长的超时时间以支持 AI 流式响应
#-----------------------------------------------------------------------------
- name: conversation-service
url: http://conversation-service:3004
connect_timeout: 60000
write_timeout: 120000
read_timeout: 120000
retries: 2
routes:
- name: conversation-routes
paths:
- /api/v1/conversations
- /api/v1/messages
strip_path: false
preserve_host: true
methods:
- GET
- POST
- PUT
- PATCH
- DELETE
- OPTIONS
#-----------------------------------------------------------------------------
# Evolution Service - 进化服务
#-----------------------------------------------------------------------------
- name: evolution-service
url: http://evolution-service:3005
connect_timeout: 60000
write_timeout: 60000
read_timeout: 60000
retries: 3
routes:
- name: evolution-routes
paths:
- /api/v1/evolution
- /api/v1/admin
strip_path: false
preserve_host: true
methods:
- GET
- POST
- PUT
- PATCH
- DELETE
- OPTIONS
#-----------------------------------------------------------------------------
# File Service - 文件管理服务
#-----------------------------------------------------------------------------
- name: file-service
url: http://file-service:3006
connect_timeout: 60000
write_timeout: 300000
read_timeout: 300000
retries: 2
routes:
- name: file-routes
paths:
- /api/v1/files
strip_path: false
preserve_host: true
methods:
- GET
- POST
- PUT
- PATCH
- DELETE
- OPTIONS
#===============================================================================
# 全局插件配置
#===============================================================================
plugins:
#-----------------------------------------------------------------------------
# CORS - 跨域资源共享
#-----------------------------------------------------------------------------
- name: cors
config:
origins:
- https://iconsulting.szaiai.com
- http://localhost:5173
- http://localhost:3000
methods:
- GET
- POST
- PUT
- PATCH
- DELETE
- OPTIONS
headers:
- Accept
- Accept-Version
- Content-Type
- Content-Length
- Authorization
- X-User-Id
- X-Request-Id
exposed_headers:
- X-Request-Id
credentials: true
max_age: 3600
preflight_continue: false
#-----------------------------------------------------------------------------
# Request Transformer - 添加请求头
#-----------------------------------------------------------------------------
# - name: request-transformer
# config:
# add:
# headers:
# - X-Kong-Proxy: "true"
#-----------------------------------------------------------------------------
# Rate Limiting - 请求限流 (可选)
#-----------------------------------------------------------------------------
# - name: rate-limiting
# config:
# minute: 100
# hour: 1000
# policy: local
# fault_tolerant: true
# hide_client_headers: false
#-----------------------------------------------------------------------------
# Request Size Limiting - 请求大小限制
#-----------------------------------------------------------------------------
# - name: request-size-limiting
# config:
# allowed_payload_size: 10
# size_unit: megabytes
#===============================================================================
# 消费者配置 (用于认证)
#===============================================================================
# consumers:
# - username: web-client
# keyauth_credentials:
# - key: your-api-key-here
# - username: admin-client
# keyauth_credentials:
# - key: your-admin-api-key-here