aboutsummaryrefslogtreecommitdiff
path: root/backend/server.py
diff options
context:
space:
mode:
authorTerry Truong <terry06890@gmail.com>2022-06-27 21:03:51 +1000
committerTerry Truong <terry06890@gmail.com>2022-06-27 21:28:10 +1000
commit96bb515a603499abb016d381f0bdb5bd51ebda92 (patch)
tree9a1f4331b942bdbe33418ff67bf3d5f8a338e147 /backend/server.py
parent761eef9a720b8fb85786ba4dc84805fdcc0d7d48 (diff)
Enable client directly using server URL, while avoiding CORS restrictions
Diffstat (limited to 'backend/server.py')
-rwxr-xr-xbackend/server.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/backend/server.py b/backend/server.py
index 879c51d..a1f1585 100755
--- a/backend/server.py
+++ b/backend/server.py
@@ -12,6 +12,7 @@ dbFile = "data/data.db"
imgDir = "../public/img/"
DEFAULT_SUGG_LIM = 5
MAX_SUGG_LIM = 50
+CORS_ANY_ORIGIN = True # Used during development to avoid Cross-Origin Resource Sharing restrictions
usageInfo = f"""
Usage: {sys.argv[0]}
@@ -312,9 +313,12 @@ class DbServer(BaseHTTPRequestHandler):
return
self.send_response(404)
def respondJson(self, val):
+ global CORS_ANY_ORIGIN
content = jsonpickle.encode(val, unpicklable=False).encode("utf-8")
self.send_response(200)
self.send_header("Content-type", "application/json")
+ if CORS_ANY_ORIGIN:
+ self.send_header("Access-Control-Allow-Origin", "*")
if "accept-encoding" in self.headers and "gzip" in self.headers["accept-encoding"]:
if len(content) > 100:
content = gzip.compress(content, compresslevel=5)