Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI, Depends, HTTPException, status | |
| from fastapi.responses import JSONResponse | |
| import uvicorn | |
| from dotenv import load_dotenv | |
| # --- Load .env file BEFORE importing other modules --- | |
| load_dotenv() | |
| # Import routers from other files | |
| from .auth import AuthRouter | |
| from .skus import SkuRouter | |
| from .barcodes import BarcodeRouter | |
| # Import the database connection | |
| from .db import db | |
| from fastapi.middleware.cors import CORSMiddleware | |
| # --- App Initialization --- | |
| app = FastAPI( | |
| title="HF Masala Barcode System API", | |
| description="Internal API for managing SKUs and EAN-13 barcodes.", | |
| version="1.0.0" | |
| ) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # --- Include Routers --- | |
| app.include_router(AuthRouter) | |
| app.include_router(SkuRouter) | |
| app.include_router(BarcodeRouter) | |
| # --- Test Endpoint --- | |
| async def get_health(): | |
| """ | |
| A simple health check endpoint to confirm the API is running. | |
| """ | |
| return JSONResponse( | |
| status_code=status.HTTP_200_OK, | |
| content={"status": "ok", "message": "HF Masala API is running!"} | |
| ) | |
| # --- Main Entry Point (for running with 'python -m app.main') --- | |
| if __name__ == "__main__": | |
| print("Starting HF Masala API server...") |