Spaces:
Sleeping
Sleeping
testing render
Browse files- src/app/app.py +8 -2
- src/app/database/db.py +9 -4
src/app/app.py
CHANGED
|
@@ -37,8 +37,14 @@ app = FastAPI(
|
|
| 37 |
|
| 38 |
app.add_middleware(
|
| 39 |
CORSMiddleware,
|
| 40 |
-
allow_origins=[
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
allow_methods=["*"],
|
| 43 |
allow_headers=["*"],
|
| 44 |
)
|
|
|
|
| 37 |
|
| 38 |
app.add_middleware(
|
| 39 |
CORSMiddleware,
|
| 40 |
+
allow_origins=[
|
| 41 |
+
"http://localhost:5173",
|
| 42 |
+
"http://localhost:5173/",
|
| 43 |
+
"http://127.0.0.1:5173",
|
| 44 |
+
"http://127.0.0.1:5173/",
|
| 45 |
+
"https://cdebookly.onrender.com",
|
| 46 |
+
],
|
| 47 |
+
allow_credentials=True,
|
| 48 |
allow_methods=["*"],
|
| 49 |
allow_headers=["*"],
|
| 50 |
)
|
src/app/database/db.py
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
|
|
| 1 |
from collections.abc import AsyncGenerator
|
| 2 |
-
import uuid
|
| 3 |
-
from sqlalchemy import Column, Integer, String, ForeignKey, Text, DateTime
|
| 4 |
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine, async_sessionmaker
|
| 5 |
-
from sqlalchemy.orm import DeclarativeBase, relationship
|
| 6 |
|
|
|
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
engine = create_async_engine(DATABASE_URL)
|
| 11 |
async_session_maker = async_sessionmaker(engine, class_=AsyncSession)
|
|
|
|
| 1 |
+
import os
|
| 2 |
from collections.abc import AsyncGenerator
|
|
|
|
|
|
|
| 3 |
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine, async_sessionmaker
|
|
|
|
| 4 |
|
| 5 |
+
DATABASE_URL = os.getenv("DATABASE_URL")
|
| 6 |
|
| 7 |
+
if not DATABASE_URL:
|
| 8 |
+
DATABASE_URL = "sqlite+aiosqlite:///./codebookly_testing.db"
|
| 9 |
+
else:
|
| 10 |
+
if DATABASE_URL.startswith("postgres://"):
|
| 11 |
+
DATABASE_URL = DATABASE_URL.replace("postgres://", "postgresql+asyncpg://", 1)
|
| 12 |
+
elif DATABASE_URL.startswith("postgresql://") and "+asyncpg" not in DATABASE_URL:
|
| 13 |
+
DATABASE_URL = DATABASE_URL.replace("postgresql://", "postgresql+asyncpg://", 1)
|
| 14 |
|
| 15 |
engine = create_async_engine(DATABASE_URL)
|
| 16 |
async_session_maker = async_sessionmaker(engine, class_=AsyncSession)
|