47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
# app/main.py
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.routers import address, contact, proposal, dewar, shipment, puck, spreadsheet
|
|
from app.database import Base, engine, SessionLocal, load_sample_data
|
|
|
|
app = FastAPI()
|
|
|
|
# Apply CORS middleware
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"], # Enable CORS for all origins
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
|
|
@app.on_event("startup")
|
|
def on_startup():
|
|
# Drop and recreate database schema
|
|
Base.metadata.drop_all(bind=engine)
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
db = SessionLocal()
|
|
try:
|
|
load_sample_data(db)
|
|
finally:
|
|
db.close()
|
|
|
|
|
|
# Include routers with correct configuration
|
|
app.include_router(contact.router, prefix="/contacts", tags=["contacts"])
|
|
app.include_router(address.router, prefix="/addresses", tags=["addresses"])
|
|
app.include_router(proposal.router, prefix="/proposals", tags=["proposals"])
|
|
app.include_router(dewar.router, prefix="/dewars", tags=["dewars"])
|
|
app.include_router(shipment.router, prefix="/shipments", tags=["shipments"])
|
|
app.include_router(puck.router, prefix="/pucks", tags=["pucks"])
|
|
app.include_router(spreadsheet.router, tags=["spreadsheet"])
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
|
|
uvicorn.run(app, host="127.0.0.1", port=8000, log_level="debug")
|