Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔀 Enable CORS in cfc_webapp #977

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions emission/net/api/cfc_webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,18 @@ def after_request():
msTimeNow, duration)
stats.store_server_api_time(request.params.user_uuid, "%s_%s_cputime" % (request.method, request.path),
msTimeNow, new_duration)

# add headers to allow CORS (Cross-Origin Resource Sharing)
# Note: this is only needed for requests made from browsers (i.e. JavaScript fetch)
# Requests made from native phone code do not have rules about CORS
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'

# generic route accepting OPTIONS method, needed for CORS preflight
@route('/<:re:.*>', method='OPTIONS')
def enable_cors_generic_route():
pass

# Auth helpers BEGIN
# This should only be used by createUserProfile since we may not have a UUID
Expand Down
Loading