2022-02-13 20:38:02 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
from flask import Flask
|
|
|
|
from flask_restful import Api
|
|
|
|
from healthcheck import HealthCheck
|
|
|
|
from utils import Config, register_all_error_handlers, health_database_status
|
|
|
|
from model import db
|
|
|
|
from schemas import ma
|
2022-02-13 22:32:40 +01:00
|
|
|
from resources import MealBaseResource, MealIndividualResource
|
2022-02-13 20:38:02 +01:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
app.config.from_object(Config)
|
|
|
|
|
|
|
|
api = Api(app)
|
|
|
|
health = HealthCheck()
|
|
|
|
ma.init_app(app)
|
2022-02-13 21:12:25 +01:00
|
|
|
db.init_app(app)
|
2022-02-13 20:38:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
@app.before_first_request
|
|
|
|
def init_db():
|
|
|
|
db.create_all()
|
|
|
|
|
|
|
|
|
|
|
|
api.add_resource(MealBaseResource, "/meals")
|
2022-02-13 22:32:40 +01:00
|
|
|
api.add_resource(MealIndividualResource, "/meals/<mealid>")
|
2022-02-13 20:38:02 +01:00
|
|
|
|
|
|
|
health.add_check(health_database_status)
|
|
|
|
|
|
|
|
register_all_error_handlers(app)
|
|
|
|
|
|
|
|
app.add_url_rule("/healthz", "healthcheck", view_func=lambda: health.run())
|
|
|
|
|
|
|
|
if __name__ != '__main__':
|
|
|
|
import logging
|
|
|
|
|
|
|
|
gunicorn_logger = logging.getLogger('gunicorn.error')
|
|
|
|
app.logger.handlers = gunicorn_logger.handlers
|
|
|
|
app.logger.setLevel(gunicorn_logger.level)
|