1
+ import json
1
2
import os
2
3
import subprocess
3
4
import sys
@@ -65,7 +66,7 @@ def run(self):
65
66
pid .write ()
66
67
67
68
try :
68
- self .add_github_codespace_support ()
69
+ self .add_csrf_trusted_origins ()
69
70
self .run_preflight ()
70
71
self .add_gunicorn ()
71
72
self .add_tailwind ()
@@ -78,17 +79,22 @@ def run(self):
78
79
finally :
79
80
pid .rm ()
80
81
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
92
98
93
99
def run_preflight (self ):
94
100
if subprocess .run (["bolt" , "preflight" ], env = self .bolt_env ).returncode :
0 commit comments