Esempio n. 1
0
def create_app():
    dotenv.load_dotenv(dotenv_path=".env")

    app = Flask(__name__,
                static_url_path="/static/",
                static_folder=os.path.join(APP_PATH, "src"),
                template_folder=os.path.join(APP_PATH, "src"))
    app.url_map.strict_slashes = False

    FLASK_ENV = os.environ.get("FLASK_ENV", "production").lower()
    if FLASK_ENV == "development":
        app.config.from_object("app.config.DevelopmentConfig")
    else:
        app.config.from_object("app.config.ProductionConfig")

    SECRET_KEY = app.config.get("SECRET_KEY") or os.environ.get(
        "SECRET_KEY", None)
    if not SECRET_KEY:
        raise ValueError("No SECRET_KEY set for Flask application")
    app.config["SECRET_KEY"] = SECRET_KEY

    @app.context_processor
    def override_url_for():
        return dict(url_for=dated_url_for)

    with app.app_context():
        CORS(app=app, resources={r"*": {"origin": "*"}})
        init_routes()

    return app
Esempio n. 2
0
def init(app, config):
    app.config.from_object(config)

    db.init_app(app)

    init_routes(app)

    Session(app)

    @app.errorhandler(HttpError)
    def handle_invalid_usage(error):
        return error.content, error.status_code
Esempio n. 3
0
def init_app() -> web.Application:
    app = web.Application()
    with open(PATH / '..' / 'config.yml', 'r') as stream:
        conf = yaml.load(stream)

    init_routes(app)
    app['config'] = conf

    logging.basicConfig(level=logging.DEBUG)
    log.debug(app['config'])

    app.on_startup.extend([init_redis])
    app.on_cleanup.extend([close_redis])

    return app
Esempio n. 4
0
def create_app():

    app = Flask(__name__)

    app.config.from_pyfile("config.py")
    db.init_app(app)

    # Flask-RESTful init
    init_routes(app)

    # For db commits
    app.app_context().push()
    db.create_all()

    return app
def create_app():
    from app.routes import init_routes
    import db

    app = FastAPI()
    app.add_middleware(
        CORSMiddleware,
        allow_origins=["*"],
        allow_credentials=True,
        allow_methods=["*"],
        allow_headers=["*"],
    )
    init_routes(app)
    db.initialize_database()

    @app.get("/", include_in_schema=False)
    def index():
        return RedirectResponse(url="/docs")

    @app.get("/alive")
    def alive():
        return {"message": "Hello World"}

    return app
Esempio n. 6
0
async def create_app() -> Application:
    app = Application()
    handler = AppHandler()
    init_routes(app, handler)
    init_jinja2(app)
    return app
Esempio n. 7
0
    g.start = [time.time(), request.base_url]
    g.reported_time = app.config.get('REPORTED_TIME')


@app.after_request
def after_request(response):
    if 'start' in g:
        start, url = g.start
        end = time.time()
        diff = end - float(start)
        logfile.debug("API -> {}, time -> {}".format(url, str(diff)))

    return response


init_routes(app)


def jwt_error_handler(message):
    return response_error(message)


def needs_fresh_token_callback():
    return response_error('Only fresh tokens are allowed')


def revoked_token_callback():
    return response_error('Token has been revoked')


def expired_token_callback():
"""
Initialize Flask application.
"""
from flask import Flask
from flask_cors import CORS
from flask_restful import Api

from app.door import Door

app = Flask(__name__)

api = Api(app)
CORS(app)

door = Door()

# initialize routes
from app import routes

routes.init_routes(api)