Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Commit

Permalink
Added CORS headers to the JSON RPC API response
Browse files Browse the repository at this point in the history
  • Loading branch information
metachris committed Feb 26, 2018
1 parent 7ffa337 commit 898f8a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion neo/api/JSONRPC/JsonRpcApi.py
Expand Up @@ -17,7 +17,7 @@
from neo import __version__
from neo.Settings import settings
from neo.Core.Blockchain import Blockchain
from neo.api.utils import json_response
from neo.api.utils import json_response, cors_header
from neo.Core.State.AccountState import AccountState
from neo.Core.TX.Transaction import Transaction
from neocore.UInt160 import UInt160
Expand Down Expand Up @@ -81,6 +81,7 @@ def __init__(self, port):
#
@app.route('/')
@json_response
@cors_header
def home(self, request):
# {"jsonrpc": "2.0", "id": 5, "method": "getblockcount", "params": []}
body = None
Expand Down
11 changes: 11 additions & 0 deletions neo/api/utils.py
Expand Up @@ -11,3 +11,14 @@ def wrapper(self, request, *args, **kwargs):
request.setHeader('Content-Type', 'application/json')
return json.dumps(res) if isinstance(res, dict) else res
return wrapper


# @cors_header decorator to add the CORS headers
def cors_header(func):
""" @cors_header decorator adds CORS headers """
@wraps(func)
def wrapper(self, request, *args, **kwargs):
res = func(self, request, *args, **kwargs)
request.setHeader('Access-Control-Allow-Origin', '*')
return res
return wrapper

0 comments on commit 898f8a8

Please sign in to comment.