bcns-gameDistributionSystem/bcnsGDSAPI/__init__.py
odecif 77b0bcb94a Prepare API for gunicorn
It is now possible to run the API with gunicorn using
gunicorn -w 4 -b 0.0.0.0:8001 'bcnsGDSAPI:create_app()'.

Also did other small changes.
2023-11-21 12:51:35 +01:00

53 lines
1.3 KiB
Python

from flask import request, jsonify, Flask
import json
from datetime import date
import tomllib
import sys
import os
class MyJSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, date):
return o.isoformat()
return super().default(o)
def create_app(test_config=None):
app = Flask(__name__, instance_relative_config=True)
app.config['JSON_AS_ASCII'] = False
if test_config is None:
app.config.from_file('bcnsgdsapi-config.toml',
load=tomllib.load, text=False)
else:
app.config.from_mapping(test_config)
try:
os.makedirs(app.instance_path)
except OSError:
pass
import bcnsGDSAPI.modules.db_connect
bcnsGDSAPI.modules.db_connect.init(app.config)
from bcnsGDSAPI.modules.gamelist import gamelist
from bcnsGDSAPI.modules.game import game
app.register_blueprint(gamelist)
app.register_blueprint(game)
# Just a simple homepage, nothing fancy
@app.route('/', methods=['GET'])
def home():
if 'id' not in request.args:
return "<h1>BCNS Game Distribution System</h1><p>API-endpoint</p>"
else:
return jsonify("I see you're a man of culture as well")
return app
if __name__ == "__main__":
app = create_app()
app.run(host="0.0.0.0", port=8001, debug=True)