File size: 1,769 Bytes
55d0d9e
 
 
 
39ef4f8
55d0d9e
 
 
 
 
39ef4f8
55d0d9e
 
 
39ef4f8
cb3c17f
39ef4f8
cb3c17f
 
39ef4f8
40113d9
 
39ef4f8
40113d9
 
 
55d0d9e
 
 
 
 
 
 
 
 
 
 
 
 
 
863464b
 
 
 
 
 
 
 
55d0d9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware  
from contextlib import asynccontextmanager
from sqlalchemy.ext.asyncio import create_async_engine
from app.api.routes import (
    codes, chapters, agencies, definitions, 
    comittee_designations, index, sections
)
import logging
import os

log = logging.getLogger(__name__)

DATABASE_URL = os.getenv("DATABASE_URL")
# DATABASE_URL = "sqlite+aiosqlite:///./codebookly_testing.db"

# if DATABASE_URL and DATABASE_URL.startswith("postgres://"):
#     DATABASE_URL = DATABASE_URL.replace("postgres://", "postgresql+asyncpg://", 1)

if not DATABASE_URL:
    log.warning("DATABASE_URL not found. Database features will be unavailable.")
else:
    if DATABASE_URL.startswith("postgres://"):
        DATABASE_URL = DATABASE_URL.replace("postgres://", "postgresql+asyncpg://", 1)
        
@asynccontextmanager
async def lifespan(app: FastAPI):
    print("Starting up...")
    yield
    print("Shutting down...")

app = FastAPI(
    title="Codebookly",
    description="Codebookly study platform",
    lifespan=lifespan,
)

app.add_middleware(
    CORSMiddleware,
    allow_origins=[
        "http://localhost:5173",
        "http://localhost:5173/",
        "http://127.0.0.1:5173",
        "http://127.0.0.1:5173/",
        "https://cdebookly.onrender.com",
    ],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

app.include_router(codes.router)
app.include_router(chapters.router)
app.include_router(agencies.router)
app.include_router(comittee_designations.router)
app.include_router(definitions.router)  
app.include_router(index.router)
app.include_router(sections.router)

@app.get("/health")
def health_check():
    return {"status": "ok"}