Skip to content

Commit 8000c67

Browse files
committed
Only set dev allowed hosts and csrf origins if they are not in the env already
1 parent 22c2e28 commit 8000c67

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

plain-dev/plain/dev/cli.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -352,24 +352,26 @@ def modify_hosts_file(self):
352352
sys.exit(1)
353353

354354
def set_csrf_and_allowed_hosts(self):
355-
csrf_trusted_origins = json.dumps(
356-
[
357-
self.url,
358-
]
359-
)
360-
allowed_hosts = json.dumps([self.hostname])
361-
362-
# Set environment variables
363-
self.plain_env["PLAIN_CSRF_TRUSTED_ORIGINS"] = csrf_trusted_origins
364-
self.custom_process_env["PLAIN_CSRF_TRUSTED_ORIGINS"] = csrf_trusted_origins
365-
366-
self.plain_env["PLAIN_ALLOWED_HOSTS"] = allowed_hosts
367-
self.custom_process_env["PLAIN_ALLOWED_HOSTS"] = allowed_hosts
355+
if "PLAIN_CSRF_TRUSTED_ORIGINS" not in os.environ:
356+
csrf_trusted_origins = json.dumps(
357+
[
358+
self.url,
359+
]
360+
)
361+
self.plain_env["PLAIN_CSRF_TRUSTED_ORIGINS"] = csrf_trusted_origins
362+
self.custom_process_env["PLAIN_CSRF_TRUSTED_ORIGINS"] = csrf_trusted_origins
363+
click.secho(
364+
f"Automatically set PLAIN_CSRF_TRUSTED_ORIGINS={csrf_trusted_origins}",
365+
dim=True,
366+
)
368367

369-
click.secho(
370-
f"Automatically set PLAIN_ALLOWED_HOSTS={allowed_hosts} PLAIN_CSRF_TRUSTED_ORIGINS={csrf_trusted_origins}",
371-
dim=True,
372-
)
368+
if "PLAIN_ALLOWED_HOSTS" not in os.environ:
369+
allowed_hosts = json.dumps([self.hostname])
370+
self.plain_env["PLAIN_ALLOWED_HOSTS"] = allowed_hosts
371+
self.custom_process_env["PLAIN_ALLOWED_HOSTS"] = allowed_hosts
372+
click.secho(
373+
f"Automatically set PLAIN_ALLOWED_HOSTS={allowed_hosts}", dim=True
374+
)
373375

374376
def run_preflight(self):
375377
click.echo()

0 commit comments

Comments
 (0)