forked from LBRYCommunity/lbry-sdk
fix cross scripting problem
add access-control-allow-origin: http://localhost:5279
This commit is contained in:
parent
02bde900d6
commit
5072f503c4
1 changed files with 31 additions and 1 deletions
|
@ -11,6 +11,7 @@ import requests
|
|||
|
||||
from twisted.web import server, resource, static
|
||||
from twisted.internet import defer, threads, error, reactor
|
||||
from txjsonrpc import jsonrpclib
|
||||
from txjsonrpc.web import jsonrpc
|
||||
from jsonrpc.proxy import JSONRPCProxy
|
||||
|
||||
|
@ -64,6 +65,35 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
|||
"""
|
||||
isLeaf = True
|
||||
|
||||
def render(self, request):
|
||||
request.content.seek(0, 0)
|
||||
# Unmarshal the JSON-RPC data.
|
||||
content = request.content.read()
|
||||
parsed = jsonrpclib.loads(content)
|
||||
functionPath = parsed.get("method")
|
||||
args = parsed.get('params')
|
||||
id = parsed.get('id')
|
||||
version = parsed.get('jsonrpc')
|
||||
if version:
|
||||
version = int(float(version))
|
||||
elif id and not version:
|
||||
version = jsonrpclib.VERSION_1
|
||||
else:
|
||||
version = jsonrpclib.VERSION_PRE1
|
||||
# XXX this all needs to be re-worked to support logic for multiple
|
||||
# versions...
|
||||
try:
|
||||
function = self._getFunction(functionPath)
|
||||
except jsonrpclib.Fault, f:
|
||||
self._cbRender(f, request, id, version)
|
||||
else:
|
||||
request.setHeader('Access-Control-Allow-Origin', ('http://localhost' + ':' + str(API_PORT)))
|
||||
request.setHeader("content-type", "text/json")
|
||||
d = defer.maybeDeferred(function, *args)
|
||||
d.addErrback(self._ebRender, id)
|
||||
d.addCallback(self._cbRender, request, id, version)
|
||||
return server.NOT_DONE_YET
|
||||
|
||||
def setup(self, wallet_type, check_for_updates):
|
||||
def _set_vars(wallet_type, check_for_updates):
|
||||
reactor.addSystemEventTrigger('before', 'shutdown', self._shutdown)
|
||||
|
|
Loading…
Reference in a new issue