403Webshell
Server IP : 3.147.158.171  /  Your IP : 216.73.216.216
Web Server : Apache/2.4.67 (Amazon Linux) OpenSSL/3.5.5
System : Linux ip-172-31-2-178.us-east-2.compute.internal 6.1.172-216.329.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Wed May 20 06:31:34 UTC 2026 x86_64
User : ec2-user ( 1000)
PHP Version : 8.4.21
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /tsai/www/html/api.johnturman.net/app/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /tsai/www/html/api.johnturman.net/app/main.py
from typing import Union
import os
import logging
from logging.handlers import RotatingFileHandler
from pathlib import Path
from dotenv import load_dotenv

# Load environment variables FIRST, before any app imports
env_path = Path(__file__).parent.parent / '.env'
load_dotenv(dotenv_path=env_path)

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api.v1.routes import api_router

# Configure logging with rotating file handler (same as CLI scripts)
# Writes to logs/api.log so API and CLI logs are unified
log_dir = Path(__file__).parent.parent / 'logs'
log_dir.mkdir(exist_ok=True)
log_path = log_dir / 'api.log'

# Set log level from environment variable (default: INFO)
log_level = logging.DEBUG if os.environ.get('LOG_LEVEL', '').upper() == 'DEBUG' else logging.INFO

handler = RotatingFileHandler(log_path, maxBytes=10*1024*1024, backupCount=5)
handler.setFormatter(logging.Formatter(
    '%(levelname)s %(asctime)s %(filename)s ln %(lineno)s %(message)s',
    datefmt='%m/%d/%Y %I:%M:%S %p'
))
logging.basicConfig(level=log_level, handlers=[handler])

# Validate environment variables
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
ANTHROPIC_API_KEY = os.environ.get("ANTHROPIC_API_KEY")

if not OPENAI_API_KEY:
    logging.error(f"OPENAI_API_KEY not found. Environment file path: {env_path}")
    raise EnvironmentError("Failed to find OPENAI_API_KEY in environment variables")

if not ANTHROPIC_API_KEY:
    logging.warning("ANTHROPIC_API_KEY not found. Claude models will not be available.")
else:
    logging.info("Both OpenAI and Anthropic API keys loaded successfully")

app = FastAPI()

# CORS allowlist: wildcard matches every subdomain we serve in prod + dev.
# Browsers will block any other origin; the API itself identifies the calling
# site by parsing this same Origin header (see utilities/site_auth.py).
ALLOWED_ORIGIN_REGEX = (
    r"^https?://("
    r"localhost(:\d+)?"
    r"|([a-z0-9-]+\.)*turmansolutions\.(ai|test)"
    r"|([a-z0-9-]+\.)*johnturman\.(net|test)"
    r"|([a-z0-9-]+\.)*scike\.(ai|test)"
    r")$"
)

app.add_middleware(
    CORSMiddleware,
    allow_origin_regex=ALLOWED_ORIGIN_REGEX,
    allow_credentials=False,
    allow_methods=["GET", "POST", "PATCH", "PUT", "DELETE", "OPTIONS"],
    allow_headers=["content-type", "accept", "authorization"],
)

app.include_router(api_router, prefix="/api/v1")


# @app.get("/")
# def read_root():
#     return {"Hello": "World"}


# @app.get("/items/{item_id}")
# def read_item(item_id: int, q: Union[str, None] = None):
#     return {"item_id": item_id, "q": q}

Youez - 2016 - github.com/yon3zu
LinuXploit