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

45 lines
1.2 KiB
Python
Raw Normal View History

2018-04-27 08:47:24 +00:00
# App initialization
2018-05-03 14:40:30 +00:00
from flask_api import FlaskAPI
2018-04-26 12:51:37 +00:00
from flask_sqlalchemy import SQLAlchemy
2018-05-04 13:44:17 +00:00
from flask_bcrypt import Bcrypt
2018-05-07 14:13:07 +00:00
from flasgger import Swagger
2018-05-17 22:39:45 +00:00
from flask_cors import CORS
2018-05-03 14:40:30 +00:00
app = FlaskAPI(__name__, instance_relative_config=True)
app.config.from_object('config')
2018-05-03 18:55:16 +00:00
app.config.from_pyfile('config.py', silent=True)
2018-04-26 12:51:37 +00:00
db = SQLAlchemy(app)
2018-05-04 13:44:17 +00:00
bcrypt = Bcrypt(app)
2018-05-07 14:13:07 +00:00
swagger = Swagger(app, template_file='swagger/template.yaml')
2018-05-17 22:39:45 +00:00
CORS(app)
2018-04-27 08:47:24 +00:00
2018-05-03 12:23:24 +00:00
def setup_blueprints(app):
2018-05-06 19:42:21 +00:00
"""
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 .devices import devices_bp
from .accounts import accounts_bp
from .api import api_bp
from .mqtt import mqtt_bp
2018-05-06 19:42:21 +00:00
app.register_blueprint(devices_bp)
app.register_blueprint(accounts_bp)
app.register_blueprint(mqtt_bp)
2018-05-06 19:42:21 +00:00
app.register_blueprint(api_bp, url_prefix='/api')
2018-05-03 12:23:24 +00:00
setup_blueprints(app)
2018-04-14 11:44:47 +00:00
2018-04-26 13:03:38 +00:00
2018-04-14 11:44:47 +00:00
@app.route("/")
2018-05-07 14:13:07 +00:00
def root():
2018-04-14 11:44:47 +00:00
return "Hello World!"