-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.py
More file actions
79 lines (62 loc) · 2.57 KB
/
Copy pathapp.py
File metadata and controls
79 lines (62 loc) · 2.57 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
app.py — Flask application entry point
Loads .env automatically when imported (needed for local dev & WSGI).
"""
import os
import sys
# Load environment variables from .env (does nothing if .env is absent)
try:
from dotenv import load_dotenv
load_dotenv()
except Exception:
pass
# Ensure current directory is in path
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
if BASE_DIR not in sys.path:
sys.path.insert(0, BASE_DIR)
# Front-end files (HTML/CSS/JS/audio/favicon) live in ./frontend
FRONTEND_DIR = os.path.join(BASE_DIR, 'frontend')
from flask import Flask, send_from_directory
from flask_cors import CORS
from config import Config
from extensions import db, bcrypt, jwt
from api_routes.auth import auth_bp
from api_routes.admin import admin_bp
from api_routes.student import student_bp
from api_routes.quiz import quiz_bp
from api_routes.leaderboard import leaderboard_bp
from api_routes.ai import ai_bp # NVIDIA NIM AI
from banner import print_banner
# Show the ASCII welcome banner on startup — fires for `python app.py` and when
# gunicorn/wsgi imports this module (so it also lands in the server boot logs).
# Guard against Flask's debug auto-reloader, which re-executes this module in a
# child process (WERKZEUG_RUN_MAIN=true); without this the banner prints twice
# and would re-appear on every hot-reload.
if os.environ.get('WERKZEUG_RUN_MAIN') != 'true':
print_banner()
def create_app():
app = Flask(__name__)
app.config.from_object(Config)
CORS(app, origins=["https://code-escape-room-kk9h.onrender.com", "http://localhost:5000", "http://127.0.0.1:5000"])
db.init_app(app)
bcrypt.init_app(app)
jwt.init_app(app)
app.register_blueprint(auth_bp, url_prefix='/api/auth')
app.register_blueprint(admin_bp, url_prefix='/api/admin')
app.register_blueprint(student_bp, url_prefix='/api/student')
app.register_blueprint(quiz_bp, url_prefix='/api/quiz')
app.register_blueprint(leaderboard_bp, url_prefix='/api/leaderboard')
app.register_blueprint(ai_bp, url_prefix='/api/ai')
@app.route('/')
def index():
return send_from_directory(FRONTEND_DIR, 'login.html')
@app.route('/<path:filename>')
def serve_file(filename):
return send_from_directory(FRONTEND_DIR, filename)
@app.route('/health')
def health():
return {'status': 'ok', 'message': 'Code Escape Room API is running'}, 200
return app
if __name__ == '__main__':
app = create_app()
app.run(debug=True, port=5000)