major claude changes
This commit is contained in:
@@ -3,7 +3,6 @@ import os
|
||||
def load_config(mode=os.environ.get('MODE')):
|
||||
|
||||
try:
|
||||
print(f"mode is {mode}")
|
||||
if mode == 'PRODUCTION':
|
||||
from settings_prod import ApplicationConfig
|
||||
return ApplicationConfig
|
||||
|
||||
46
main.py
46
main.py
@@ -1,11 +1,39 @@
|
||||
import logging
|
||||
import sys
|
||||
from fastapi import FastAPI
|
||||
from app.routers import delivery
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from config import load_config
|
||||
from sqlalchemy import create_engine, text
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
|
||||
ApplicationConfig = load_config()
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
handlers=[logging.StreamHandler(sys.stdout)]
|
||||
)
|
||||
logger = logging.getLogger('eamco_money_api')
|
||||
|
||||
# Database setup
|
||||
engine = create_engine(ApplicationConfig.SQLALCHEMY_DATABASE_URI)
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
def check_db_connection():
|
||||
"""
|
||||
Test database connectivity.
|
||||
"""
|
||||
try:
|
||||
db = SessionLocal()
|
||||
db.execute(text("SELECT 1"))
|
||||
db.close()
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@@ -23,3 +51,21 @@ app.add_middleware(
|
||||
@app.get("/")
|
||||
def read_root():
|
||||
return {"Status": "Money Service is online"}
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
"""Application startup - log configuration and test DB connection."""
|
||||
logger.info("🚀 eamco_money_api STARTING")
|
||||
mode = ApplicationConfig.CURRENT_SETTINGS.upper()
|
||||
if mode in ['DEVELOPMENT', 'DEV']:
|
||||
logger.info("🤖🤖🤖🤖🤖 Mode: Development 🤖🤖🤖🤖🤖")
|
||||
elif mode in ['PRODUCTION', 'PROD']:
|
||||
logger.info("💀💀💀💀💀💀💀💀💀💀 ⚠️ WARNING PRODUCTION 💀💀💀💀💀💀💀💀💀💀")
|
||||
logger.info(f"DB: {ApplicationConfig.SQLALCHEMY_DATABASE_URI[:30]}...")
|
||||
logger.info(f"CORS: {len(ApplicationConfig.origins)} origins configured")
|
||||
|
||||
# Test database connection
|
||||
if check_db_connection():
|
||||
logger.info("DB Connection: ✅ OK")
|
||||
else:
|
||||
logger.info("DB Connection: ❌ FAILED")
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
fastapi
|
||||
uvicorn[standard]
|
||||
psycopg2-binary
|
||||
sqlalchemy
|
||||
# eamco_money_api dependencies
|
||||
# FastAPI web framework and server
|
||||
fastapi==0.115.6
|
||||
uvicorn[standard]==0.34.0
|
||||
|
||||
# Database
|
||||
SQLAlchemy==2.0.40
|
||||
psycopg2-binary==2.9.10
|
||||
|
||||
@@ -1,24 +1,27 @@
|
||||
import os
|
||||
|
||||
|
||||
class ApplicationConfig:
|
||||
"""
|
||||
Basic Configuration for a generic User
|
||||
Local Configuration (LAN deployment)
|
||||
"""
|
||||
CURRENT_SETTINGS = 'LOCAL'
|
||||
# databases info
|
||||
POSTGRES_USERNAME = 'postgres'
|
||||
POSTGRES_PW = 'password'
|
||||
POSTGRES_SERVER = '192.168.1.204'
|
||||
POSTGRES_PORT = '5432'
|
||||
POSTGRES_DBNAME00 = 'auburnoil'
|
||||
SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}/{}".format(POSTGRES_USERNAME,
|
||||
|
||||
# Database credentials from environment variables
|
||||
POSTGRES_USERNAME = os.environ.get('POSTGRES_USERNAME', 'postgres')
|
||||
POSTGRES_PW = os.environ.get('POSTGRES_PW')
|
||||
POSTGRES_SERVER = os.environ.get('POSTGRES_SERVER', '192.168.1.204')
|
||||
POSTGRES_PORT = os.environ.get('POSTGRES_PORT', '5432')
|
||||
POSTGRES_DBNAME00 = os.environ.get('POSTGRES_DBNAME', 'auburnoil')
|
||||
|
||||
SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}/{}".format(
|
||||
POSTGRES_USERNAME,
|
||||
POSTGRES_PW,
|
||||
POSTGRES_SERVER,
|
||||
POSTGRES_DBNAME00
|
||||
)
|
||||
SQLALCHEMY_BINDS = {'auburnoil': SQLALCHEMY_DATABASE_URI}
|
||||
|
||||
|
||||
origins = [
|
||||
"http://192.168.1.204:9000",
|
||||
"http://192.168.1.204:9613",
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
import os
|
||||
|
||||
|
||||
class ApplicationConfig:
|
||||
"""
|
||||
Basic Configuration for a generic User
|
||||
Production Configuration
|
||||
"""
|
||||
CURRENT_SETTINGS = 'PRODUCTION'
|
||||
# databases info
|
||||
POSTGRES_USERNAME = 'postgres'
|
||||
POSTGRES_PW = 'password'
|
||||
POSTGRES_SERVER = '192.168.1.204'
|
||||
POSTGRES_PORT = '5432'
|
||||
POSTGRES_DBNAME00 = 'auburnoil'
|
||||
SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}/{}".format(POSTGRES_USERNAME,
|
||||
|
||||
# Database credentials from environment variables
|
||||
POSTGRES_USERNAME = os.environ.get('POSTGRES_USERNAME', 'postgres')
|
||||
POSTGRES_PW = os.environ.get('POSTGRES_PW')
|
||||
POSTGRES_SERVER = os.environ.get('POSTGRES_SERVER', '192.168.1.204')
|
||||
POSTGRES_PORT = os.environ.get('POSTGRES_PORT', '5432')
|
||||
POSTGRES_DBNAME00 = os.environ.get('POSTGRES_DBNAME', 'auburnoil')
|
||||
|
||||
SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}/{}".format(
|
||||
POSTGRES_USERNAME,
|
||||
POSTGRES_PW,
|
||||
POSTGRES_SERVER,
|
||||
POSTGRES_DBNAME00
|
||||
|
||||
Reference in New Issue
Block a user