fix cross scripting problem

add access-control-allow-origin: http://localhost:5279
This commit is contained in:
Jack 2016-03-20 22:53:01 -04:00
parent 02bde900d6
commit 5072f503c4

View file

@ -11,6 +11,7 @@ import requests
from twisted.web import server, resource, static from twisted.web import server, resource, static
from twisted.internet import defer, threads, error, reactor from twisted.internet import defer, threads, error, reactor
from txjsonrpc import jsonrpclib
from txjsonrpc.web import jsonrpc from txjsonrpc.web import jsonrpc
from jsonrpc.proxy import JSONRPCProxy from jsonrpc.proxy import JSONRPCProxy
@ -64,6 +65,35 @@ class LBRYDaemon(jsonrpc.JSONRPC):
""" """
isLeaf = True 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 setup(self, wallet_type, check_for_updates):
def _set_vars(wallet_type, check_for_updates): def _set_vars(wallet_type, check_for_updates):
reactor.addSystemEventTrigger('before', 'shutdown', self._shutdown) reactor.addSystemEventTrigger('before', 'shutdown', self._shutdown)
@ -1206,4 +1236,4 @@ class LBRYDaemonWeb(resource.Resource):
d.addCallbacks(lambda results: self._delayed_render(request, results), d.addCallbacks(lambda results: self._delayed_render(request, results),
lambda err: self._delayed_render(request, json.dumps({'message': err.getTraceback(), 'code': BAD_REQUEST}))) lambda err: self._delayed_render(request, json.dumps({'message': err.getTraceback(), 'code': BAD_REQUEST})))
return server.NOT_DONE_YET return server.NOT_DONE_YET