From 239e0bb729fd209d4bc66dca64bf3cabb8f84ccb Mon Sep 17 00:00:00 2001 From: Krateng Date: Fri, 30 Nov 2018 16:01:32 +0100 Subject: [PATCH] Some fixing --- database.py | 1 + server.py | 12 +++++++----- utilities.py | 6 ++++++ 3 files changed, 14 insertions(+), 5 deletions(-) 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() +