Skip to content

Commit

Permalink
gg
Browse files Browse the repository at this point in the history
  • Loading branch information
upayanmazumder committed Nov 28, 2024
1 parent 3ee1e90 commit ee20419
Showing 1 changed file with 44 additions and 11 deletions.
55 changes: 44 additions & 11 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,29 @@
from dotenv import load_dotenv

# Load environment variables from the .env file
load_dotenv()
if load_dotenv():
print(".env file loaded successfully.")
else:
print("No .env file found or failed to load. Ensure environment variables are set.")

# List of required environment variables for Firebase
required_env_vars = [
"FIREBASE_PROJECT_ID",
"FIREBASE_PRIVATE_KEY_ID",
"FIREBASE_PRIVATE_KEY",
"FIREBASE_CLIENT_EMAIL",
"FIREBASE_CLIENT_ID",
"FIREBASE_AUTH_URI",
"FIREBASE_TOKEN_URI",
"FIREBASE_AUTH_PROVIDER_CERT_URL",
"FIREBASE_CLIENT_CERT_URL"
]

# Check for missing environment variables
missing_vars = [var for var in required_env_vars if not os.getenv(var)]
if missing_vars:
print(f"Error: Missing required environment variables: {', '.join(missing_vars)}")
exit(1) # Exit the application if critical variables are missing

# Initialize the Flask app
app = Flask(__name__)
Expand All @@ -26,23 +48,34 @@
"client_x509_cert_url": os.getenv("FIREBASE_CLIENT_CERT_URL")
}

# Initialize Firebase Admin SDK with the credentials from the environment variables
cred = credentials.Certificate(firebase_credentials)
firebase_admin.initialize_app(cred)
try:
# Initialize Firebase Admin SDK
cred = credentials.Certificate(firebase_credentials)
firebase_admin.initialize_app(cred)

# Initialize Firestore
db = firestore.client()
print("Firebase Admin SDK initialized successfully.")

# Initialize Firestore
db = firestore.client()
except Exception as e:
print(f"Error initializing Firebase Admin SDK: {e}")
db = None # Graceful fallback if Firebase initialization fails

# Import and register blueprints
from auth.signup import signup_bp
from auth.login import login_bp
try:
from auth.signup import signup_bp
from auth.login import login_bp

app.register_blueprint(signup_bp)
app.register_blueprint(login_bp)
app.register_blueprint(signup_bp)
app.register_blueprint(login_bp)
print("Auth blueprints registered successfully.")
except ImportError as e:
print(f"Error importing blueprints: {e}")

@app.route('/')
def home():
return "Welcome to the Flask App"

if __name__ == '__main__':
app.run(debug=True, port=3000)
port = int(os.getenv("PORT", 3000)) # Default to port 3000 if not specified
app.run(debug=True, port=port)

0 comments on commit ee20419

Please sign in to comment.