Spaces:
Sleeping
Sleeping
Commit ·
8909c04
1
Parent(s): 9cdda17
Set the front end
Browse files
main.py
CHANGED
|
@@ -3,8 +3,6 @@ import sys
|
|
| 3 |
from pathlib import Path
|
| 4 |
from fastapi import FastAPI
|
| 5 |
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
-
from fastapi.responses import FileResponse
|
| 7 |
-
from fastapi.staticfiles import StaticFiles
|
| 8 |
from sqlalchemy import inspect, text
|
| 9 |
|
| 10 |
sys.path.append(str(Path(__file__).parent))
|
|
@@ -20,7 +18,6 @@ Base.metadata.create_all(bind=engine)
|
|
| 20 |
|
| 21 |
def _ensure_schema():
|
| 22 |
inspector = inspect(engine)
|
| 23 |
-
|
| 24 |
migrations = {
|
| 25 |
"invoices": {
|
| 26 |
"patient_name": "VARCHAR",
|
|
@@ -31,12 +28,10 @@ def _ensure_schema():
|
|
| 31 |
"shade": "VARCHAR",
|
| 32 |
},
|
| 33 |
}
|
| 34 |
-
|
| 35 |
with engine.begin() as conn:
|
| 36 |
for table_name, columns in migrations.items():
|
| 37 |
if not inspector.has_table(table_name):
|
| 38 |
continue
|
| 39 |
-
|
| 40 |
existing_columns = {col["name"] for col in inspector.get_columns(table_name)}
|
| 41 |
for column_name, column_type in columns.items():
|
| 42 |
if column_name in existing_columns:
|
|
@@ -47,24 +42,15 @@ _ensure_schema()
|
|
| 47 |
|
| 48 |
app = FastAPI(title="SmiloCAD API", redirect_slashes=False)
|
| 49 |
|
| 50 |
-
BASE_DIR = Path(__file__).resolve().parent.parent
|
| 51 |
-
FRONTEND_DIR = BASE_DIR / "frontend"
|
| 52 |
-
|
| 53 |
-
app.mount("/css", StaticFiles(directory=FRONTEND_DIR / "css"), name="css")
|
| 54 |
-
app.mount("/js", StaticFiles(directory=FRONTEND_DIR / "js"), name="js")
|
| 55 |
-
app.mount("/img", StaticFiles(directory=FRONTEND_DIR / "img"), name="img")
|
| 56 |
-
|
| 57 |
app.add_middleware(
|
| 58 |
CORSMiddleware,
|
| 59 |
-
allow_origins=[
|
| 60 |
-
"https://smilocard.vercel.app",
|
| 61 |
-
],
|
| 62 |
allow_methods=["*"],
|
| 63 |
allow_headers=["*"],
|
| 64 |
)
|
| 65 |
|
| 66 |
@app.get("/")
|
| 67 |
def root():
|
| 68 |
-
return
|
| 69 |
|
| 70 |
-
app.include_router(invoice_router, prefix="/api")
|
|
|
|
| 3 |
from pathlib import Path
|
| 4 |
from fastapi import FastAPI
|
| 5 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
|
|
| 6 |
from sqlalchemy import inspect, text
|
| 7 |
|
| 8 |
sys.path.append(str(Path(__file__).parent))
|
|
|
|
| 18 |
|
| 19 |
def _ensure_schema():
|
| 20 |
inspector = inspect(engine)
|
|
|
|
| 21 |
migrations = {
|
| 22 |
"invoices": {
|
| 23 |
"patient_name": "VARCHAR",
|
|
|
|
| 28 |
"shade": "VARCHAR",
|
| 29 |
},
|
| 30 |
}
|
|
|
|
| 31 |
with engine.begin() as conn:
|
| 32 |
for table_name, columns in migrations.items():
|
| 33 |
if not inspector.has_table(table_name):
|
| 34 |
continue
|
|
|
|
| 35 |
existing_columns = {col["name"] for col in inspector.get_columns(table_name)}
|
| 36 |
for column_name, column_type in columns.items():
|
| 37 |
if column_name in existing_columns:
|
|
|
|
| 42 |
|
| 43 |
app = FastAPI(title="SmiloCAD API", redirect_slashes=False)
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
app.add_middleware(
|
| 46 |
CORSMiddleware,
|
| 47 |
+
allow_origins=["https://smilocard.vercel.app"],
|
|
|
|
|
|
|
| 48 |
allow_methods=["*"],
|
| 49 |
allow_headers=["*"],
|
| 50 |
)
|
| 51 |
|
| 52 |
@app.get("/")
|
| 53 |
def root():
|
| 54 |
+
return {"status": "SmiloCAD API running"}
|
| 55 |
|
| 56 |
+
app.include_router(invoice_router, prefix="/api")
|