run server if main, cleanup
This commit is contained in:
24
server.py
24
server.py
@@ -4,29 +4,26 @@ import json
|
|||||||
import anydbm as dbm
|
import anydbm as dbm
|
||||||
import os
|
import os
|
||||||
|
|
||||||
if (os.path.dirname(__file__) != ""):
|
|
||||||
os.chdir(os.path.dirname(__file__))
|
|
||||||
|
|
||||||
data = dbm.open("cryptopad.db", 'c');
|
data = dbm.open("cryptopad.db", 'c');
|
||||||
|
|
||||||
@get("/storage/<key>")
|
@get("/storage/<key>")
|
||||||
def getItem(key):
|
def getItem(key):
|
||||||
if (data.has_key(key)):
|
if (data.has_key(key)):
|
||||||
return json.dumps(data[key])
|
return json.dumps(data[key])
|
||||||
else:
|
else:
|
||||||
return json.dumps(None)
|
return json.dumps(None)
|
||||||
|
|
||||||
@get("/storage/delete/<key>")
|
@get("/storage/delete/<key>")
|
||||||
def delete(key):
|
def delete(key):
|
||||||
if (data.has_key(key)):
|
if (data.has_key(key)):
|
||||||
del data[key]
|
del data[key]
|
||||||
|
|
||||||
@post("/storage/<key>")
|
@post("/storage/<key>")
|
||||||
def set(key):
|
def set(key):
|
||||||
data[key] = request.forms.get("value")
|
data[key] = request.forms.get("value")
|
||||||
|
|
||||||
@route('/<filepath:path>')
|
@get("/<filepath:path>")
|
||||||
def server_static(filepath):
|
def mystatic(filepath):
|
||||||
return static_file(filepath, root='static')
|
return static_file(filepath, root='static')
|
||||||
|
|
||||||
@route('/')
|
@route('/')
|
||||||
@@ -34,3 +31,6 @@ def index():
|
|||||||
return static_file("cryptopad.html", root='static')
|
return static_file("cryptopad.html", root='static')
|
||||||
|
|
||||||
application=default_app()
|
application=default_app()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run(application, host='localhost', port=55580)
|
||||||
|
|||||||
Reference in New Issue
Block a user