Commit 7a6e992c authored by Jogi Hofmüller's avatar Jogi Hofmüller

Add handling of static files

parent b4f44ae0
......@@ -4,17 +4,38 @@ import json
from libgg3 import Gdb
import os
import sys
from mimetypes import guess_type
def logmsg(msg):
print('{}: {}'.format(strftime('%c'), msg))
gdbfile = '/app/data/gdb.json'
gdbfile = '/app/data/gdb/gdb.json'
# dir for static html files; mainly needed for letsencrypt's ceertbot
basedir = '/app/data/www'
gdb = Gdb(gdbfile)
gdb.loadJSON()
gdb.fillBuffer()
# a handler for static files
class FileHandler(web.RequestHandler):
@web.asynchronous
def get(self, path):
print('path={}'.format(path))
if path == '':
# we could also just serve a geruecht here
path = 'index.html'
location = os.path.join(basedir, path)
if not os.path.isfile(location):
raise web.HTTPError(status_code=404)
content_type, _ = guess_type(location)
self.add_header('Content-Type', content_type)
with open(location) as source_file:
self.finish(source_file.read())
class RestHandler(web.RequestHandler):
def set_default_headers(self):
......@@ -80,6 +101,7 @@ def run():
sys.exit(2)
app = web.Application([
web.url(r'/(.*)', FileHandler),
web.url(r'/get', GeruechtHandler),
web.url(r'/login/user/([.0-9a-zA-Z@]+)/password/([0-9a-zA-Z]+)', LoginHandler),
web.url(r'/edit/geruecht/id/([0-9]+)', EditHandler),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment