Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
aa.gusti
/
opensipkd-base
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 6f5ab239
authored
Jul 17, 2025
by
aa.gustiana@gmail.com
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Refactor CORS headers handling and improve logging for debugging
1 parent
1eb5b827
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
5 deletions
opensipkd/base/__init__.py
opensipkd/base/__init__.py
View file @
6f5ab23
...
...
@@ -3,6 +3,7 @@ import importlib
import
inspect
import
locale
import
logging
from
math
import
log
from
sqlalchemy
import
or_
import
re
from
.routes
import
routes
...
...
@@ -82,6 +83,7 @@ def add_cors_headers_response_callback(event):
origin
=
request
.
headers
.
get
(
"Origin"
,
None
)
allowed_origin
=
get_params
(
"allowed_origin"
,
None
)
if
allowed_origin
:
_logging
.
debug
(
f
"Allowed Origin: {origin}"
)
if
origin
not
in
allowed_origin
.
split
(
'
\n
'
):
origin
=
"null"
...
...
@@ -95,19 +97,34 @@ def add_cors_headers_response_callback(event):
# {'Access-Control-Allow-Credential': 'true',
# 'Access-Control-Allow-Origin': "*"}
# )
if
origin
:
headers
[
'Access-Control-Allow-Origin'
]
=
origin
else
:
#
if origin:
#
headers['Access-Control-Allow-Origin'] = origin
#
else:
headers
[
'Access-Control-Allow-Origin'
]
=
"*"
if
'Access-Control-Allow-Credentials'
not
in
headers
:
headers
[
'Access-Control-Allow-Credentials'
]
=
'true'
# _logging.info
(f"Headers: {headers}")
_logging
.
debug
(
f
"Headers: {headers}"
)
response
.
headers
.
update
(
headers
)
event
.
request
.
add_response_callback
(
cors_headers
)
# def add_cors_headers_response_callback(event):
# def cors_headers(request, response):
# response.headers.update({
# 'Access-Control-Allow-Origin': '*',
# 'Access-Control-Allow-Methods': 'POST,GET,DELETE,PUT,OPTIONS',
# 'Access-Control-Allow-Headers': 'Origin, Content-Type, Accept, Authorization, userid, key, signature',
# 'Access-Control-Allow-Credentials': 'true',
# 'Access-Control-Max-Age': '1728000',
# })
# _logging.debug(f"Request Origin: {request.headers.get('Origin', None)}")
# _logging.debug(f"Response Headers: {response.headers}")
# event.request.add_response_callback(cors_headers)
# https://groups.google.com/forum/#!topic/pylons-discuss/QIj4G82j04c
def
has_permission_
(
request
,
perm_names
,
context
=
None
):
if
not
perm_names
:
...
...
@@ -702,7 +719,7 @@ def main(global_config, **settings):
engine
=
engine_from_config
(
settings
,
'sqlalchemy.'
,
client_encoding
=
'utf8'
,
max_identifier_length
=
30
,
pool_pre_ping
=
True
)
# , convert_unicode=True
max_identifier_length
=
30
)
# , convert_unicode=True
DBSession
.
configure
(
bind
=
engine
)
LogDBSession
.
configure
(
bind
=
engine
)
Base
.
metadata
.
bind
=
engine
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment