Shield external portal jumps (keep EXTERNAL_* for later), serve /nav from static build, and proxy /book + /community to vertical Next apps with Caddy notes. Co-authored-by: Cursor <cursoragent@cursor.com>
75 lines
2.0 KiB
Python
75 lines
2.0 KiB
Python
"""FastAPI application — ebook backend (modular, feature-flag driven)."""
|
|
|
|
import logging
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from .config import get_settings
|
|
from .features import is_enabled
|
|
from .pb_schema import create_collections
|
|
|
|
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s %(levelname)s %(message)s")
|
|
|
|
app = FastAPI(title="Ebook Backend", docs_url="/api/docs", openapi_url="/api/openapi.json")
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=[
|
|
"https://book.nomadro.com",
|
|
"https://nomadro.com",
|
|
"http://localhost:3000",
|
|
],
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
|
|
# ── Conditionally register routers based on feature flags ───
|
|
|
|
if is_enabled("payment.crypto.enabled"):
|
|
from .routers import pay
|
|
app.include_router(pay.router)
|
|
|
|
if is_enabled("payment.checkout.enabled"):
|
|
from .routers import creem
|
|
app.include_router(creem.router)
|
|
|
|
if is_enabled("feedback.enabled"):
|
|
from .routers import feedback
|
|
app.include_router(feedback.router)
|
|
|
|
if is_enabled("userdata.enabled"):
|
|
from .routers import userdata
|
|
app.include_router(userdata.router)
|
|
|
|
from .routers import admin
|
|
app.include_router(admin.router)
|
|
|
|
|
|
@app.on_event("startup")
|
|
def _ensure_pb_schema():
|
|
# Create collections if not exist. Safe to call repeatedly.
|
|
try:
|
|
create_collections()
|
|
except Exception:
|
|
# Don't block service startup due to schema initialization
|
|
pass
|
|
|
|
|
|
@app.get("/api/health")
|
|
async def health():
|
|
s = get_settings()
|
|
return {
|
|
"status": "ok",
|
|
"modules": {
|
|
"crypto_pay": is_enabled("payment.crypto.enabled"),
|
|
"checkout_pay": is_enabled("payment.checkout.enabled"),
|
|
"feedback": is_enabled("feedback.enabled"),
|
|
"userdata": is_enabled("userdata.enabled"),
|
|
"pocketbase": is_enabled("backend.pocketbase.enabled"),
|
|
"email": is_enabled("backend.email.enabled"),
|
|
"admin": True,
|
|
},
|
|
}
|