Skip to content

Commit f7ed841

Browse files
authored
Update CORS and build workflow to use vars for environment variables (#164)
* fix(docker): update Docker build workflow to use vars for environment variables * feat(cors): add API_CORS_ALLOWED_ORIGINS to .env.example and update settings for dynamic CORS configuration
1 parent eb1cc12 commit f7ed841

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

.github/workflows/docker-build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ jobs:
6060
file: ./docker/client/Dockerfile
6161
push: true
6262
build-args: |
63-
NEXT_PUBLIC_BACKEND_URL_BASE=${{ secrets.NEXT_PUBLIC_BACKEND_URL_BASE }}
64-
NEXT_PUBLIC_BACKEND_URL=${{ secrets.NEXT_PUBLIC_BACKEND_URL }}
63+
NEXT_PUBLIC_BACKEND_URL_BASE=${{ vars.NEXT_PUBLIC_BACKEND_URL_BASE }}
64+
NEXT_PUBLIC_BACKEND_URL=${{ vars.NEXT_PUBLIC_BACKEND_URL }}
6565
tags: |
6666
${{ vars.DOCKERHUB_USERNAME }}/wajo-prod-client:latest
6767
${{ vars.DOCKERHUB_USERNAME }}/wajo-prod-client:${{ env.date }}

server/.env.example

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ APP_NAME=DjangoAPI
33
APP_ENV=DEVELOPMENT
44
API_SECRET_KEY="supersecretkey"
55
API_ALLOWED_HOSTS=".localhost 127.0.0.1 [::1]"
6+
API_CORS_ALLOWED_ORIGINS="http://localhost:3000 https://localhost:3000"
67

78
POSTGRES_HOST=localhost
89
POSTGRES_NAME=postgres

server/api/settings.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@
110110
"corsheaders.middleware.CorsMiddleware",
111111
]
112112

113-
CORS_ALLOWED_ORIGINS = [
114-
"http://localhost:3000",
115-
"http://127.0.0.1:3000",
116-
FRONTEND_URL,
117-
]
113+
CORS_ALLOWED_ORIGINS = (
114+
os.environ.get("API_CORS_ALLOWED_ORIGINS").split(" ")
115+
if os.environ.get("API_CORS_ALLOWED_ORIGINS")
116+
else []
117+
) + [FRONTEND_URL]
118118

119119
ROOT_URLCONF = "api.urls"
120120

0 commit comments

Comments
 (0)