Skip to content

Commit e7a814e

Browse files
committed
Add GO_WEB_INTERNAL_URL for local development
To test playwright exports using local running go-web-app
1 parent f29c3c3 commit e7a814e

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

api/serializers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,9 +2436,9 @@ def create(self, validated_data):
24362436
title = "Export"
24372437
user = self.context["request"].user
24382438
if export_type == Export.ExportType.PER:
2439-
validated_data["url"] = f"https://{settings.FRONTEND_URL}/countries/{country_id}/{export_type}/{export_id}/export/"
2439+
validated_data["url"] = f"{settings.GO_WEB_INTERNAL_URL}/countries/{country_id}/{export_type}/{export_id}/export/"
24402440
else:
2441-
validated_data["url"] = f"https://{settings.FRONTEND_URL}/{export_type}/{export_id}/export/"
2441+
validated_data["url"] = f"{settings.GO_WEB_INTERNAL_URL}/{export_type}/{export_id}/export/"
24422442

24432443
# Adding is_pga to the url
24442444
is_pga = validated_data.pop("is_pga")

api/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def build_storage_state(tmp_dir, user, token):
2525
state = {
2626
"origins": [
2727
{
28-
"origin": "https://" + settings.FRONTEND_URL + "/",
28+
"origin": settings.GO_WEB_INTERNAL_URL + "/",
2929
"localStorage": [
3030
{
3131
"name": "user",

docker-compose.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ x-server: &base_server_setup
1515
# Other development defaults configs
1616
DJANGO_DEBUG: ${DJANGO_DEBUG:-true}
1717
GO_ENVIRONMENT: ${GO_ENVIRONMENT:-development}
18-
API_FQDN: ${API_FQDN:-localhost:8000}
19-
FRONTEND_URL: ${FRONTEND_URL:-localhost:3000}
18+
API_FQDN: ${API_FQDN:-http://localhost:8000}
19+
FRONTEND_URL: ${FRONTEND_URL:-http://localhost:3000}
20+
GO_WEB_INTERNAL_URL: ${GO_WEB_INTERNAL_URL:-http://host.docker.internal:3000}
21+
DJANGO_ADDITIONAL_ALLOWED_HOSTS: ${DJANGO_ADDITIONAL_ALLOWED_HOSTS:-host.docker.internal}
2022
DEBUG_EMAIL: ${DEBUG_EMAIL:-true}
2123
MOLNIX_API_BASE: ${MOLNIX_API_BASE:-https://api.ifrc-staging.rpm.molnix.com/api/}
2224
ERP_API_ENDPOINT: ${ERP_API_ENDPOINT:-https://ifrctintapim001.azure-api.net/GoAPI/ExtractGoEmergency}

main/settings.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#
3333
API_FQDN=str, # https://goadmin.ifrc.org
3434
FRONTEND_URL=str, # https://go.ifrc.org
35+
GO_WEB_INTERNAL_URL=(str, None), # http://host.docker.internal
3536
# Database
3637
DJANGO_DB_NAME=str,
3738
DJANGO_DB_USER=str,
@@ -130,12 +131,18 @@
130131

131132
# Requires uppercase variable https://docs.djangoproject.com/en/2.1/topics/settings/#creating-your-own-settings
132133

134+
def find_env_with_value(*keys: str) -> None | str:
135+
for key in keys:
136+
if env(key):
137+
return key
133138

134-
def parse_domain(env_key: str) -> str:
139+
140+
def parse_domain(*env_keys: str) -> str:
135141
"""
136142
NOTE: This is used for to avoid breaking due to existing config value
137143
Update this using django validation
138144
"""
145+
env_key = find_env_with_value(*env_keys)
139146
raw_domain = env(env_key)
140147
domain = raw_domain
141148
if not domain.startswith("http"):
@@ -146,6 +153,9 @@ def parse_domain(env_key: str) -> str:
146153

147154
GO_API_URL = parse_domain("API_FQDN")
148155
GO_WEB_URL = parse_domain("FRONTEND_URL")
156+
# NOTE: Used in local development to get to the frontend service from within go-api container
157+
# GO_WEB_URL will be used if GO_WEB_INTERNAL_URL is not provided
158+
GO_WEB_INTERNAL_URL = parse_domain("GO_WEB_INTERNAL_URL", "FRONTEND_URL")
149159
FRONTEND_URL = urlparse(GO_WEB_URL).hostname # XXX: Deprecated. Slowly remove this from codebase
150160

151161
INTERNAL_IPS = ["127.0.0.1"]

0 commit comments

Comments
 (0)