Example #1
0
from flask_sqlalchemy import SQLAlchemy
from flask import jsonify
from dhr_logging.logger import DHRLogger

from app.config import APP_NAME
from app.config import SECRET_KEY
from app.config import SQLALCHEMY_DATABASE_URI
from app.config import SQLALCHEMY_COMMIT_ON_TEARDOWN

app = Flask(__name__)

api = Api(app, prefix="/api/v0.1")

app_log = DHRLogger.getLogger("dhr.source")

app.config["APP_NAME"] = APP_NAME
app.config["SECRET_KEY"] = SECRET_KEY
app.config["SQLALCHEMY_COMMIT_ON_TEARDOWN"] = SQLALCHEMY_COMMIT_ON_TEARDOWN
app.config["SQLALCHEMY_DATABASE_URI"] = SQLALCHEMY_DATABASE_URI

db = SQLAlchemy(app)

from views import api_0_1

app.register_blueprint(api_0_1)

# CORS
@app.after_request
def after_request(response):
    response.headers.add("Access-Control-Allow-Origin", "*")
    response.headers.add("Access-Control-Allow-Headers", "Content-Type,Authorization")
import logging, os
from flask import Flask
from flask_mail import Mail

logger = logging.getLogger("python")
logger.setLevel(logging.WARNING)
mail = Mail()
app = Flask(__name__)
app.config.from_object("config.{}Config".format(os.environ.get("SERVER_ENV", "Development")))
app.config["SQLALCHEMY_DATABASE_URI"] = app.config["SQLALCHEMY_DATABASE_URI"].format(
    os.environ.get("DB_USER"), os.environ.get("DB_PASS"), os.environ.get("DB_HOST"), os.environ.get("DB_NAME")
)
app.config["APP_NAME"] = app.config["APP_NAME"].format(os.environ.get("NAME", "API"))
app.config["SECRET_KEY"] = app.config["SECRET_KEY"].format(os.environ.get("SECRET_KEY", "SECRET"))
app.config["SECURITY_PASSWORD_SALT"] = app.config["SECURITY_PASSWORD_SALT"].format(
    os.environ.get("SECURITY_PASSWORD_SALT")
)