university-final-iot-backend/app/core.py

52 lines
1.5 KiB
Python
Raw Normal View History

2018-09-20 20:05:03 +00:00
# App initialization
2018-11-03 17:11:52 +00:00
from flask import Flask
2018-09-20 20:05:03 +00:00
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from flask_mail import Mail
2018-09-20 20:05:03 +00:00
from flasgger import Swagger
from flask_cors import CORS
from .tasks import celery_configurator
2018-09-20 20:05:03 +00:00
2018-11-03 17:11:52 +00:00
app = Flask(__name__, instance_relative_config=True)
2018-09-20 20:05:03 +00:00
app.config.from_object('config')
app.config.from_pyfile('config.py', silent=True)
db = SQLAlchemy(app)
bcrypt = Bcrypt(app)
mail = Mail(app)
2018-09-20 20:05:03 +00:00
swagger = Swagger(app, template_file='swagger/template.yaml')
2018-10-08 20:09:01 +00:00
swagger.template['info']['version'] = app.config['APP_VERSION']
2018-09-20 20:05:03 +00:00
CORS(app)
celery = celery_configurator.make_celery(app)
def setup_blueprints(app):
"""
Sets up all of the blueprints for application
All blueprints should be imported in this method and then added
API blueprint should expose all resources, while other
blueprints expose other domain specific functionalities
They are exposed as blueprints just for consistency, otherwise
they are just simple python packages/modules
"""
from .accounts.blueprint import accounts_bp
from .devices.blueprint import devices_bp
from .dashboards.blueprint import dashboard_bp
from .api.blueprint import api_bp
from .mqtt.blueprint import mqtt_bp
2018-09-20 20:05:03 +00:00
app.register_blueprint(accounts_bp)
app.register_blueprint(devices_bp)
app.register_blueprint(dashboard_bp)
app.register_blueprint(mqtt_bp)
app.register_blueprint(api_bp, url_prefix='/api')
setup_blueprints(app)
@app.route("/")
def root():
return "Hello World!"