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
|
2018-10-10 18:54:38 +00:00
|
|
|
from flask_mail import Mail
|
2018-09-20 20:05:03 +00:00
|
|
|
from flasgger import Swagger
|
|
|
|
from flask_cors import CORS
|
2018-10-06 11:38:27 +00:00
|
|
|
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)
|
2018-10-10 18:54:38 +00:00
|
|
|
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
|
|
|
|
"""
|
2018-10-06 11:38:27 +00:00
|
|
|
from .accounts.blueprint import accounts_bp
|
2018-10-06 11:50:53 +00:00
|
|
|
from .devices.blueprint import devices_bp
|
2018-10-06 11:46:32 +00:00
|
|
|
from .dashboards.blueprint import dashboard_bp
|
2018-10-06 12:07:40 +00:00
|
|
|
from .api.blueprint import api_bp
|
2018-10-06 11:54:49 +00:00
|
|
|
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!"
|