Spaces:
Sleeping
Sleeping
Create backend/app/main.py
Browse files- backend/app/main.py +30 -0
backend/app/main.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from fastapi import FastAPI
|
| 3 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
+
from .db import Base, engine
|
| 5 |
+
|
| 6 |
+
# Ensure data directory exists (for SQLite file)
|
| 7 |
+
os.makedirs("data", exist_ok=True)
|
| 8 |
+
|
| 9 |
+
# Create tables
|
| 10 |
+
Base.metadata.create_all(bind=engine)
|
| 11 |
+
|
| 12 |
+
app = FastAPI(title="Document Capture Demo – Backend")
|
| 13 |
+
|
| 14 |
+
# Allow CORS from anywhere (fine for a demo Space)
|
| 15 |
+
app.add_middleware(
|
| 16 |
+
CORSMiddleware,
|
| 17 |
+
allow_origins=["*"],
|
| 18 |
+
allow_credentials=True,
|
| 19 |
+
allow_methods=["*"],
|
| 20 |
+
allow_headers=["*"],
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
@app.get("/ping")
|
| 25 |
+
def ping():
|
| 26 |
+
"""
|
| 27 |
+
Simple health check endpoint.
|
| 28 |
+
You can hit this from the browser to confirm backend is running.
|
| 29 |
+
"""
|
| 30 |
+
return {"status": "ok", "message": "backend alive"}
|