Skip to content

Commit b1e4918

Browse files
committed
Configure CORS Allowed Origins via ConfigMaps
1 parent cedc58a commit b1e4918

7 files changed

Lines changed: 37 additions & 1 deletion

File tree

deploy/manifests/balancer/base/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ spec:
2121
envFrom:
2222
- secretRef:
2323
name: balancer-config
24+
- configMapRef:
25+
name: balancer-config
2426
ports:
2527
- containerPort: 8000
2628
readinessProbe:

deploy/manifests/balancer/base/kustomization.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ resources:
66
- deployment.yaml
77
- service.yaml
88
- ingress.yaml
9+
10+
configMapGenerator:
11+
- name: balancer-config
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: balancer-config
5+
data:
6+
CORS_ALLOWED_ORIGINS: "https://balancerproject.org"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
resources:
5+
- ../../base
6+
7+
patches:
8+
- path: configmap.yaml
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: balancer-config
5+
data:
6+
CORS_ALLOWED_ORIGINS: "https://sandbox.balancertestsite.com"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
resources:
5+
- ../../base
6+
7+
patches:
8+
- path: configmap.yaml

server/balancer_backend/settings.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@
6767

6868
ROOT_URLCONF = "balancer_backend.urls"
6969

70-
CORS_ALLOW_ALL_ORIGINS = True
70+
# CORS configuration
71+
CORS_ALLOWED_ORIGINS = os.environ.get("CORS_ALLOWED_ORIGINS", "http://localhost:3000").split(",")
72+
# Ensure no empty strings if input was empty or trailing comma
73+
CORS_ALLOWED_ORIGINS = [origin.strip() for origin in CORS_ALLOWED_ORIGINS if origin.strip()]
7174

7275
TEMPLATES = [
7376
{

0 commit comments

Comments
 (0)