fix(deploy): Initialize Firestore and Firebase Admin to fix startup
This commit is contained in:
parent
5a06158ef3
commit
54d21ab871
16
main.py
16
main.py
|
|
@ -32,6 +32,9 @@ from ml.anomaly_detector import AnomalyDetector
|
||||||
from auth.oauth_flow import get_authorization_url, exchange_code_for_token
|
from auth.oauth_flow import get_authorization_url, exchange_code_for_token
|
||||||
from auth.token_store import save_token
|
from auth.token_store import save_token
|
||||||
|
|
||||||
|
|
||||||
|
from google.cloud import firestore
|
||||||
|
import firebase_admin
|
||||||
from firebase_admin import credentials, messaging
|
from firebase_admin import credentials, messaging
|
||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
|
|
@ -47,6 +50,19 @@ app = FastAPI(
|
||||||
version="0.1.0",
|
version="0.1.0",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# ── FIREBASE & FIRESTORE INIT ───────────────────────────────────────────────
|
||||||
|
db = None
|
||||||
|
try:
|
||||||
|
# When running in Google Cloud, ADC will be used automatically.
|
||||||
|
# For local dev, `gcloud auth application-default login` is required.
|
||||||
|
firebase_admin.initialize_app()
|
||||||
|
db = firestore.Client()
|
||||||
|
print("Firestore client initialized successfully.")
|
||||||
|
except Exception as e:
|
||||||
|
# The app can still run in a limited mode without Firestore.
|
||||||
|
# Endpoints that depend on `db` will return a 500 error.
|
||||||
|
print(f"WARNING: Firestore client failed to initialize: {e}", file=sys.stderr)
|
||||||
|
|
||||||
# ── AUTH & SESSION ────────────────────────────────────────────────────────────
|
# ── AUTH & SESSION ────────────────────────────────────────────────────────────
|
||||||
# Add session middleware for storing auth state
|
# Add session middleware for storing auth state
|
||||||
app.add_middleware(SessionMiddleware, secret_key=os.environ.get("SESSION_SECRET"))
|
app.add_middleware(SessionMiddleware, secret_key=os.environ.get("SESSION_SECRET"))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user