File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
src/django_agent/forestadmin/django_agent Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change 44import threading
55from typing import Callable , Optional , Union
66
7+ from corsheaders import defaults as default_cors_settings
78from django .apps import AppConfig , apps
89from django .conf import settings
910from forestadmin .agent_toolkit .forest_logger import ForestLogger
@@ -77,6 +78,7 @@ def get_agent(cls) -> DjangoAgent:
7778 def ready (self ):
7879 # we need to wait for other apps to be ready, for this forest app must be ready
7980 # that's why we need another thread waiting for every app to be ready
81+ self .setup_cors_settings ()
8082 t = threading .Thread (name = "forest.wait_and_launch_agent" , target = self ._wait_for_all_apps_ready_and_launch_agent )
8183 t .start ()
8284
@@ -99,3 +101,13 @@ def _wait_for_all_apps_ready_and_launch_agent(self):
99101 )
100102
101103 DjangoAgentApp ._DJANGO_AGENT = init_app_agent ()
104+
105+ def setup_cors_settings (self ):
106+ # headers
107+ if getattr (settings , "CORS_ALLOW_HEADERS" , None ):
108+ allowed_headers = settings .CORS_ALLOW_HEADERS
109+ else :
110+ allowed_headers = default_cors_settings .default_headers
111+
112+ if "Forest-Context-Url" not in allowed_headers :
113+ settings .CORS_ALLOW_HEADERS = (* allowed_headers , "Forest-Context-Url" )
You can’t perform that action at this time.
0 commit comments