major claude changes
This commit is contained in:
@@ -3,7 +3,6 @@ import os
|
|||||||
def load_config(mode=os.environ.get('MODE')):
|
def load_config(mode=os.environ.get('MODE')):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print(f"mode is {mode}")
|
|
||||||
if mode == 'PRODUCTION':
|
if mode == 'PRODUCTION':
|
||||||
from settings_prod import ApplicationConfig
|
from settings_prod import ApplicationConfig
|
||||||
return ApplicationConfig
|
return ApplicationConfig
|
||||||
|
|||||||
46
main.py
46
main.py
@@ -1,11 +1,39 @@
|
|||||||
|
import logging
|
||||||
|
import sys
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from app.routers import delivery
|
from app.routers import delivery
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from config import load_config
|
from config import load_config
|
||||||
|
from sqlalchemy import create_engine, text
|
||||||
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
|
||||||
|
|
||||||
ApplicationConfig = load_config()
|
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()
|
app = FastAPI()
|
||||||
|
|
||||||
@@ -23,3 +51,21 @@ app.add_middleware(
|
|||||||
@app.get("/")
|
@app.get("/")
|
||||||
def read_root():
|
def read_root():
|
||||||
return {"Status": "Money Service is online"}
|
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
|
# eamco_money_api dependencies
|
||||||
uvicorn[standard]
|
# FastAPI web framework and server
|
||||||
psycopg2-binary
|
fastapi==0.115.6
|
||||||
sqlalchemy
|
uvicorn[standard]==0.34.0
|
||||||
|
|
||||||
|
# Database
|
||||||
|
SQLAlchemy==2.0.40
|
||||||
|
psycopg2-binary==2.9.10
|
||||||
|
|||||||
@@ -1,24 +1,27 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
class ApplicationConfig:
|
class ApplicationConfig:
|
||||||
"""
|
"""
|
||||||
Basic Configuration for a generic User
|
Local Configuration (LAN deployment)
|
||||||
"""
|
"""
|
||||||
CURRENT_SETTINGS = 'LOCAL'
|
CURRENT_SETTINGS = 'LOCAL'
|
||||||
# databases info
|
|
||||||
POSTGRES_USERNAME = 'postgres'
|
# Database credentials from environment variables
|
||||||
POSTGRES_PW = 'password'
|
POSTGRES_USERNAME = os.environ.get('POSTGRES_USERNAME', 'postgres')
|
||||||
POSTGRES_SERVER = '192.168.1.204'
|
POSTGRES_PW = os.environ.get('POSTGRES_PW')
|
||||||
POSTGRES_PORT = '5432'
|
POSTGRES_SERVER = os.environ.get('POSTGRES_SERVER', '192.168.1.204')
|
||||||
POSTGRES_DBNAME00 = 'auburnoil'
|
POSTGRES_PORT = os.environ.get('POSTGRES_PORT', '5432')
|
||||||
SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}/{}".format(POSTGRES_USERNAME,
|
POSTGRES_DBNAME00 = os.environ.get('POSTGRES_DBNAME', 'auburnoil')
|
||||||
|
|
||||||
|
SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}/{}".format(
|
||||||
|
POSTGRES_USERNAME,
|
||||||
POSTGRES_PW,
|
POSTGRES_PW,
|
||||||
POSTGRES_SERVER,
|
POSTGRES_SERVER,
|
||||||
POSTGRES_DBNAME00
|
POSTGRES_DBNAME00
|
||||||
)
|
)
|
||||||
SQLALCHEMY_BINDS = {'auburnoil': SQLALCHEMY_DATABASE_URI}
|
SQLALCHEMY_BINDS = {'auburnoil': SQLALCHEMY_DATABASE_URI}
|
||||||
|
|
||||||
|
|
||||||
origins = [
|
origins = [
|
||||||
"http://192.168.1.204:9000",
|
"http://192.168.1.204:9000",
|
||||||
"http://192.168.1.204:9613",
|
"http://192.168.1.204:9613",
|
||||||
|
|||||||
@@ -1,15 +1,21 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
class ApplicationConfig:
|
class ApplicationConfig:
|
||||||
"""
|
"""
|
||||||
Basic Configuration for a generic User
|
Production Configuration
|
||||||
"""
|
"""
|
||||||
CURRENT_SETTINGS = 'PRODUCTION'
|
CURRENT_SETTINGS = 'PRODUCTION'
|
||||||
# databases info
|
|
||||||
POSTGRES_USERNAME = 'postgres'
|
# Database credentials from environment variables
|
||||||
POSTGRES_PW = 'password'
|
POSTGRES_USERNAME = os.environ.get('POSTGRES_USERNAME', 'postgres')
|
||||||
POSTGRES_SERVER = '192.168.1.204'
|
POSTGRES_PW = os.environ.get('POSTGRES_PW')
|
||||||
POSTGRES_PORT = '5432'
|
POSTGRES_SERVER = os.environ.get('POSTGRES_SERVER', '192.168.1.204')
|
||||||
POSTGRES_DBNAME00 = 'auburnoil'
|
POSTGRES_PORT = os.environ.get('POSTGRES_PORT', '5432')
|
||||||
SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}/{}".format(POSTGRES_USERNAME,
|
POSTGRES_DBNAME00 = os.environ.get('POSTGRES_DBNAME', 'auburnoil')
|
||||||
|
|
||||||
|
SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}/{}".format(
|
||||||
|
POSTGRES_USERNAME,
|
||||||
POSTGRES_PW,
|
POSTGRES_PW,
|
||||||
POSTGRES_SERVER,
|
POSTGRES_SERVER,
|
||||||
POSTGRES_DBNAME00
|
POSTGRES_DBNAME00
|
||||||
|
|||||||
Reference in New Issue
Block a user