-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
56 lines (39 loc) · 1.46 KB
/
app.py
File metadata and controls
56 lines (39 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from flask import Blueprint, Flask
from flask_cors import CORS
import os
from dotenv import load_dotenv
import logging
from routes.auth import auth_bp
from routes.users import users_bp
from routes.events import events_bp
from database import close_db, init_db
from flask_jwt_extended import create_access_token
from flask_jwt_extended import get_jwt_identity
from flask_jwt_extended import jwt_required
from flask_jwt_extended import JWTManager
logger = logging.getLogger(__name__)
load_dotenv()
app = Flask(__name__)
# setup flask-jwt-extended and config options
app.config['JWT_SECRET_KEY'] = os.getenv("JWT_SECRET_KEY")
app.config['JWT_TOKEN_LOCATION'] = ["cookies"]
app.config["JWT_COOKIE_SECURE"] = False
app.config["JWT_COOKIE_SAMESITE"] = "Lax"
app.config["JWT_COOKIE_CSRF_PROTECT"] = True
jwt = JWTManager(app)
logging.basicConfig(level=logging.DEBUG)
app.logger.setLevel(logging.DEBUG)
CORS(app, origins=["http://localhost:5173"], supports_credentials=True)
# register teardown handler for db connection
app.teardown_appcontext(close_db)
# register blueprints for endpoints
api_bp = Blueprint('api', __name__, url_prefix="/api/v1")
api_bp.register_blueprint(auth_bp, url_prefix="/auth")
api_bp.register_blueprint(users_bp, url_prefix="/users")
api_bp.register_blueprint(events_bp, url_prefix="/events")
app.register_blueprint(api_bp)
# cli to initialize database
@app.cli.command("init_db")
def init_db_command():
init_db()
logger.info("Database initialized!")