Skip to content

Commit eecef22

Browse files
committed
Set localhost trusted origins in bolt dev
1 parent b95ddeb commit eecef22

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

bolt-dev/bolt/dev/cli.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import os
23
import subprocess
34
import sys
@@ -65,7 +66,7 @@ def run(self):
6566
pid.write()
6667

6768
try:
68-
self.add_github_codespace_support()
69+
self.add_csrf_trusted_origins()
6970
self.run_preflight()
7071
self.add_gunicorn()
7172
self.add_tailwind()
@@ -78,17 +79,22 @@ def run(self):
7879
finally:
7980
pid.rm()
8081

81-
def add_github_codespace_support(self):
82-
if "GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN" in os.environ:
83-
codespace_base_url = f"https://{os.environ['CODESPACE_NAME']}-{self.port}.{os.environ['GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN']}"
84-
click.secho(
85-
f"Automatically using Codespace BASE_URL={click.style(codespace_base_url, underline=True)}",
86-
bold=True,
87-
)
88-
89-
# Set BASE_URL for bolt and custom processes
90-
self.bolt_env["BASE_URL"] = codespace_base_url
91-
self.custom_process_env["BASE_URL"] = codespace_base_url
82+
def add_csrf_trusted_origins(self):
83+
if "BOLT_CSRF_TRUSTED_ORIGINS" in os.environ:
84+
return
85+
86+
csrf_trusted_origins = json.dumps(
87+
[f"http://localhost:{self.port}", f"http://127.0.0.1:{self.port}"]
88+
)
89+
90+
click.secho(
91+
f"Automatically set BOLT_CSRF_TRUSTED_ORIGINS={click.style(csrf_trusted_origins, underline=True)}",
92+
bold=True,
93+
)
94+
95+
# Set BASE_URL for bolt and custom processes
96+
self.bolt_env["BOLT_CSRF_TRUSTED_ORIGINS"] = csrf_trusted_origins
97+
self.custom_process_env["BOLT_CSRF_TRUSTED_ORIGINS"] = csrf_trusted_origins
9298

9399
def run_preflight(self):
94100
if subprocess.run(["bolt", "preflight"], env=self.bolt_env).returncode:

0 commit comments

Comments
 (0)