Skip to content

Commit

Permalink
feat: internal svc for api gateway. hub browser graphql route. remove…
Browse files Browse the repository at this point in the history
… cors from api route
  • Loading branch information
kespinola committed Feb 16, 2023
1 parent 198129f commit ba6f4c6
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 11 deletions.
2 changes: 1 addition & 1 deletion charts/hub-gateway/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: "0.2.2"
version: "0.3.0"

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
6 changes: 6 additions & 0 deletions charts/hub-gateway/plugins/kratos.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,18 @@ function _M.access(conf, ctx)
end

-- Expose user id on $kratos_user_id variable
-- Expose user email on $kratos_user_email variable
if conf.expose_user_id then
core.request.set_header(ctx, "x-user-id", data.identity.id)
core.response.set_header("x-user-id", data.identity.id)
core.request.set_header(ctx, "x-user-email", data.identity.traits.email)
core.response.set_header("x-user-email", data.identity.traits.email)
core.ctx.register_var("kratos_user_id", function(ctx)
return data.identity.id
end)
core.ctx.register_var("kratos_user_email", function(ctx)
return data.identity.traits.email
end)
end
end

Expand Down
14 changes: 5 additions & 9 deletions charts/hub-gateway/templates/apisixroute.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- $apisixPlugins := .Values.apisixPlugins -}}
{{- $namespace := .Values.hubNamespace -}}
{{- $domain:= .Values.domain -}}
{{- $domain := .Values.domain -}}
{{- $sessionCookie := .Values.sessionCookieName -}}
{{- with .Values.routes }}
{{- range . }}
Expand All @@ -20,16 +20,12 @@ spec:
websocket: {{ .websocket | default false }}
match:
hosts:
- {{ print .subdomain "." $domain | quote }}
- {{ .host | default (printf "%s.%s" .subdomain $domain) | quote }}
paths:
{{ .paths | toYaml | nindent 7 }}
{{- .paths | toYaml | nindent 8 }}
methods:
{{ .methods | toYaml | nindent 7 }}
{{- .methods | toYaml | nindent 8 }}
plugins:
{{- if .cors }}
- name: cors
enable: true
{{- end }}
{{- if .setUserHeader }}
- name: kratos
enable: true
Expand All @@ -44,7 +40,7 @@ spec:
enable: true
config:
regex_uri:
{{ .regexUri | toYaml | nindent 9 }}
{{- .regexUri | toYaml | nindent 10 }}
{{- end }}
---
{{- end }}
Expand Down
16 changes: 16 additions & 0 deletions charts/hub-gateway/templates/svc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: apisix-gateway-internal
labels:
{{- include "hub-gateway.labels" . | nindent 4 }}
spec:
type: ClusterIP
ports:
- port: 80
targetPort: 9080
protocol: TCP
name: http
selector:
app.kubernetes.io/instance: hub-gateway
app.kubernetes.io/name: apisix
31 changes: 30 additions & 1 deletion charts/hub-gateway/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,34 @@ routes:
methods:
- POST
- OPTIONS
cors: true
setUserHeader: true
regexUri:
- "/graphql"
- "/"

- name: api-internal
serviceName: federated-router
servicePort: 80
host: apisix-gateway-internal.ingress-apisix.svc.cluster.local
paths:
- /graphql
methods:
- POST
- OPTIONS
setUserHeader: true
regexUri:
- "/graphql"
- "/"

- name: hub-browser-graphql
serviceName: federated-router
servicePort: 80
subdomain: hub
paths:
- /graphql
methods:
- POST
- OPTIONS
setUserHeader: true
regexUri:
- "/graphql"
Expand Down Expand Up @@ -44,6 +71,8 @@ routes:
- /organizations/new
- /projects
- /projects/*
- /treasuries
- /treasuries/*

- name: ui-public
subdomain: hub
Expand Down

0 comments on commit ba6f4c6

Please sign in to comment.