1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Added simple API key

This commit is contained in:
Krateng
2018-11-30 15:44:30 +01:00
parent 75a70a10b7
commit 19dc86d32a
5 changed files with 32 additions and 15 deletions

View File

@@ -4,6 +4,7 @@ import _thread
import waitress
import urllib.request
import urllib.parse
from urllib.error import *
import sys
import signal
@@ -23,7 +24,7 @@ def mainpage():
# e.g. location /db { rewrite ^/db(.*)$ $1 break; proxy_pass http://yoururl:12349; }
@get("/db/<pth:path>")
def database(pth):
def database_get(pth):
keys = FormsDict.decode(request.query) # The Dal★Shabet handler
keystring = "?"
for k in keys:
@@ -35,8 +36,16 @@ def database(pth):
return contents
@post("/db/<pth:path>")
def database(pth):
contents = urllib.request.urlopen("http://localhost:" + str(DATABASE_PORT) + "/" + pth,request.body).read()
def database_post(pth):
try:
proxyresponse = urllib.request.urlopen("http://localhost:" + str(DATABASE_PORT) + "/" + pth,request.body)
contents = proxyresponse.read()
response.status = proxyresponse.getcode()
except HTTPError as e:
contents = ""
response.status = e.code
response.content_type = "application/json"
response.set_header("Access-Control-Allow-Origin","*")
return contents