Files
api7-demo/helm/api7ee-demo-k8s/templates/configmap-adc.yaml
d.viti a0dee1d499
Some checks failed
Helm Chart Build / lint-only (push) Has been skipped
Build and Deploy / build-web (push) Failing after 7s
Helm Chart Build / build-helm (push) Successful in 12s
Build and Deploy / build-api (push) Successful in 42s
Add proxy-rewrite plugin to remove /api prefix
Added proxy-rewrite plugin to strip /api prefix from requests before
forwarding to backend API microservice. The API service is a standalone
microservice that expects requests without the /api prefix.

Changes:
- Added proxy-rewrite plugin to both API routes:
  * /api/llm/* route (priority 20)
  * /api/* route (priority 10)
- Uses regex_uri to rewrite: /api/endpoint -> /endpoint

Example transformations:
- /api/health -> /health
- /api/users/123 -> /users/123
- /api/llm/chat -> /llm/chat

Plugin configuration:
  proxy-rewrite:
    regex_uri:
      - "^/api/(.*)"
      - "/$1"

This allows the API microservice to work independently without
needing to handle the /api prefix in its routes.

Reference: https://docs.api7.ai/hub/proxy-rewrite/

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-09 17:05:24 +02:00

173 lines
7.2 KiB
YAML

{{- if .Values.api7.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "api7ee.fullname" . }}-adc-config
labels:
{{- include "api7ee.labels" . | nindent 4 }}
app.kubernetes.io/component: adc
data:
adc-config.yaml: |
services:
# Web Frontend Service
- name: {{ include "api7ee.fullname" . }}-web-service
hosts:
- {{ (first .Values.api7.hosts) | quote }}
upstream:
name: {{ include "api7ee.fullname" . }}-web-upstream
scheme: http
type: roundrobin
{{- if .Values.api7.serviceDiscovery.enabled }}
# Use Kubernetes Service Discovery
discovery_type: kubernetes
{{- if .Values.api7.serviceDiscovery.namespace }}
service_name: {{ .Values.api7.serviceDiscovery.namespace }}/{{ include "api7ee.fullname" . }}-web
{{- else }}
service_name: {{ .Release.Namespace }}/{{ include "api7ee.fullname" . }}-web
{{- end }}
{{- else }}
# Static nodes configuration
nodes:
- host: {{ include "api7ee.fullname" . }}-web.{{ .Release.Namespace }}.svc.cluster.local
port: {{ .Values.web.service.port }}
weight: 100
{{- end }}
routes:
# Route for web frontend (all paths except /api)
- name: {{ include "api7ee.fullname" . }}-web-route
uris:
- /*
vars:
- - uri
- "~~"
- "^(?!/api)"
priority: 1
plugins:
{{- if .Values.api7.tls.enabled }}
redirect:
http_to_https: true
{{- end }}
{{- if .Values.api7.plugins.cors.enabled }}
cors:
allow_origins: {{ .Values.api7.plugins.cors.allowOrigins | join "," | quote }}
allow_methods: {{ .Values.api7.plugins.cors.allowMethods | join "," | quote }}
allow_headers: {{ .Values.api7.plugins.cors.allowHeaders | join "," | quote }}
expose_headers: {{ .Values.api7.plugins.cors.exposeHeaders | join "," | quote }}
max_age: {{ .Values.api7.plugins.cors.maxAge }}
allow_credential: {{ .Values.api7.plugins.cors.allowCredentials }}
{{- end }}
# API Backend Service
- name: {{ include "api7ee.fullname" . }}-api-service
hosts:
- {{ (first .Values.api7.hosts) | quote }}
upstream:
name: {{ include "api7ee.fullname" . }}-api-upstream
scheme: http
type: roundrobin
{{- if .Values.api7.serviceDiscovery.enabled }}
# Use Kubernetes Service Discovery
discovery_type: kubernetes
{{- if .Values.api7.serviceDiscovery.namespace }}
service_name: {{ .Values.api7.serviceDiscovery.namespace }}/{{ include "api7ee.fullname" . }}-api
{{- else }}
service_name: {{ .Release.Namespace }}/{{ include "api7ee.fullname" . }}-api
{{- end }}
{{- else }}
# Static nodes configuration
nodes:
- host: {{ include "api7ee.fullname" . }}-api.{{ .Release.Namespace }}.svc.cluster.local
port: {{ .Values.api.service.port }}
weight: 100
{{- end }}
routes:
# High priority route for LLM endpoints with AI rate limiting
- name: {{ include "api7ee.fullname" . }}-api-llm-route
uris:
- /api/llm
- /api/llm/*
priority: 20
plugins:
{{- if .Values.api7.tls.enabled }}
redirect:
http_to_https: true
{{- end }}
# Remove /api prefix before forwarding to backend
proxy-rewrite:
regex_uri:
- "^/api/(.*)"
- "/$1"
{{- if .Values.api7.plugins.cors.enabled }}
cors:
allow_origins: {{ .Values.api7.plugins.cors.allowOrigins | join "," | quote }}
allow_methods: {{ .Values.api7.plugins.cors.allowMethods | join "," | quote }}
allow_headers: {{ .Values.api7.plugins.cors.allowHeaders | join "," | quote }}
expose_headers: {{ .Values.api7.plugins.cors.exposeHeaders | join "," | quote }}
max_age: {{ .Values.api7.plugins.cors.maxAge }}
allow_credential: {{ .Values.api7.plugins.cors.allowCredentials }}
{{- end }}
{{- if .Values.api7.plugins.aiRateLimit.enabled }}
ai-rate-limiting:
limit: {{ .Values.api7.plugins.aiRateLimit.limit }}
time_window: {{ .Values.api7.plugins.aiRateLimit.timeWindow }}
rejected_code: {{ .Values.api7.plugins.aiRateLimit.rejectedCode }}
limit_strategy: {{ .Values.api7.plugins.aiRateLimit.limitStrategy | quote }}
{{- end }}
# Standard API route with request rate limiting
- name: {{ include "api7ee.fullname" . }}-api-route
uris:
- /api
- /api/*
priority: 10
plugins:
{{- if .Values.api7.tls.enabled }}
redirect:
http_to_https: true
{{- end }}
# Remove /api prefix before forwarding to backend
proxy-rewrite:
regex_uri:
- "^/api/(.*)"
- "/$1"
{{- if .Values.api7.plugins.cors.enabled }}
cors:
allow_origins: {{ .Values.api7.plugins.cors.allowOrigins | join "," | quote }}
allow_methods: {{ .Values.api7.plugins.cors.allowMethods | join "," | quote }}
allow_headers: {{ .Values.api7.plugins.cors.allowHeaders | join "," | quote }}
expose_headers: {{ .Values.api7.plugins.cors.exposeHeaders | join "," | quote }}
max_age: {{ .Values.api7.plugins.cors.maxAge }}
allow_credential: {{ .Values.api7.plugins.cors.allowCredentials }}
{{- end }}
{{- if .Values.api7.plugins.rateLimit.enabled }}
limit-count:
count: {{ .Values.api7.plugins.rateLimit.count }}
time_window: {{ .Values.api7.plugins.rateLimit.timeWindow }}
rejected_code: {{ .Values.api7.plugins.rateLimit.rejectedCode }}
key_type: {{ .Values.api7.plugins.rateLimit.keyType | quote }}
key: {{ .Values.api7.plugins.rateLimit.key | quote }}
{{- end }}
{{- if .Values.api7.plugins.auth.enabled }}
# API Consumers for authentication
consumers:
{{- range .Values.api7.consumers }}
- username: {{ .username }}
plugins:
key-auth:
key: {{ .apiKey }}
{{- end }}
{{- end }}
{{- if .Values.api7.plugins.logging.enabled }}
# Global Rules
global_rules:
request-logging:
plugins:
http-logger:
uri: {{ .Values.api7.plugins.logging.endpoint }}
batch_max_size: {{ .Values.api7.plugins.logging.batchMaxSize | default 1000 }}
inactive_timeout: {{ .Values.api7.plugins.logging.inactiveTimeout | default 5 }}
{{- end }}
{{- end }}