Browse Source

Fix CORS issue with allow_origin for all

Guénaël Muller 6 years ago
parent
commit
53220e8dd4
2 changed files with 8 additions and 0 deletions
  1. 3 0
      tracim/__init__.py
  2. 5 0
      tracim/lib/utils/pyramid_events.py

+ 3 - 0
tracim/__init__.py View File

@@ -3,11 +3,13 @@ import json
3 3
 import time
4 4
 
5 5
 from pyramid.config import Configurator
6
+from pyramid.events import NewResponse
6 7
 from pyramid.authentication import BasicAuthAuthenticationPolicy
7 8
 from hapic.ext.pyramid import PyramidContext
8 9
 
9 10
 from tracim.extensions import hapic
10 11
 from tracim.config import CFG
12
+from tracim.lib.utils.pyramid_events import cors_headers
11 13
 from tracim.lib.utils.request import TracimRequest
12 14
 from tracim.lib.utils.authentification import basic_auth_check_credentials
13 15
 from tracim.lib.utils.authentification import BASIC_AUTH_WEBUI_REALM
@@ -44,6 +46,7 @@ def main(global_config, **settings):
44 46
     configurator.include('pyramid_jinja2')
45 47
     # Add SqlAlchemy DB
46 48
     configurator.include('.models')
49
+    configurator.add_subscriber(cors_headers, NewResponse)
47 50
     # set Hapic
48 51
     hapic.set_context(
49 52
         PyramidContext(

+ 5 - 0
tracim/lib/utils/pyramid_events.py View File

@@ -0,0 +1,5 @@
1
+
2
+
3
+def cors_headers(context):
4
+    # TODO - G.M - 17-05-2018 - Allow to configure this header in config
5
+    context.response.headers['Access-Control-Allow-Origin'] = '*'