model-service/model_service/app.py
2020-04-13 21:14:06 +02:00

41 lines
938 B
Python

#!/usr/bin/env python3
import os
from flask import Flask
from werkzeug.middleware.proxy_fix import ProxyFix
# import stuff
from model import db
from utils import register_all_error_handlers
# import views
from views import ModelView
# create flask app
app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1)
# configure flask app
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URI', "sqlite://") # Default to memory db
# important stuff
app.secret_key = os.environ.get('SECRET_KEY', os.urandom(12))
# disable this for better performance
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# initialize stuff
db.init_app(app)
with app.app_context():
db.create_all()
# register error handlers
register_all_error_handlers(app)
# register views
for view in [ModelView]:
view.register(app, trailing_slash=False)
# start debuggig if needed
if __name__ == "__main__":
app.run(debug=True)