diff --git a/database.py b/database.py index c4a25d5..7df60dc 100644 --- a/database.py +++ b/database.py @@ -24,6 +24,7 @@ lastsync = 0 ### symmetric keys are fine for now since we hopefully use HTTPS def loadAPIkeys(): global clients + createTSV("clients/authenticated_machines.tsv") clients = parseTSV("clients/authenticated_machines.tsv","string","string") def checkAPIkey(k): diff --git a/server.py b/server.py index 0be14c9..ff413eb 100755 --- a/server.py +++ b/server.py @@ -37,18 +37,20 @@ def database_get(pth): @post("/db/") def database_post(pth): + response.set_header("Access-Control-Allow-Origin","*") try: proxyresponse = urllib.request.urlopen("http://localhost:" + str(DATABASE_PORT) + "/" + pth,request.body) contents = proxyresponse.read() response.status = proxyresponse.getcode() + response.content_type = "application/json" + return contents except HTTPError as e: - contents = "" response.status = e.code + return - - response.content_type = "application/json" - response.set_header("Access-Control-Allow-Origin","*") - return contents + + + return @route("/exit") def shutdown(): diff --git a/utilities.py b/utilities.py index b3a3f7a..77c9094 100644 --- a/utilities.py +++ b/utilities.py @@ -50,3 +50,9 @@ def parseAllTSV(path,*args): return result +def createTSV(filename): + import os + + if not os.path.exists(filename): + open(filename,"w").close() +