Command stats

This commit is contained in:
Stijn De Clercq 2021-09-07 17:16:40 +02:00
parent ce9ecc8c61
commit 41f75d7bbd
4 changed files with 47 additions and 45 deletions

15
backend/json_encoder.py Normal file
View file

@ -0,0 +1,15 @@
from datetime import date
from quart.json import JSONEncoder
class CustomEncoder(JSONEncoder):
"""
Custom JSON encoder to handle things like date parsing
"""
def default(self, o):
# Return dates as ISO strings
if isinstance(o, date):
return o.isoformat()
return super().default(o)

View file

@ -1,6 +1,7 @@
from werkzeug.exceptions import abort
from .error_handlers import handler_404, handler_422
from .json_encoder import CustomEncoder
from .routes.dm import dm_blueprint
from .routes.ping import ping_blueprint
from .routes.stats import stats_blueprint
@ -15,6 +16,7 @@ app = Quart(__name__)
# needs higher Python & Quart version
app = cors(app, allow_origin="*")
app.url_map.strict_slashes = False
app.json_encoder = CustomEncoder
# Register blueprints
app.register_blueprint(dm_blueprint)