-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
70 lines (59 loc) · 2 KB
/
main.py
File metadata and controls
70 lines (59 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from fastapi import FastAPI, HTTPException, Depends, status
from fastapi.middleware.cors import CORSMiddleware
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
from fastapi.responses import JSONResponse
import uvicorn
from dotenv import load_dotenv
import os
# Import your existing modules
from models.userModel import User
from controllers.userController import UserController
from middleware.authentication import verify_token
from middleware.error import error_handler
from routes.userRoutes import user_router
from controllers.reportController import router as report_router
# Load environment variables
load_dotenv()
# Initialize FastAPI app
app = FastAPI(
title="DataIntel Hub API",
description="A FastAPI backend for DataIntel Hub",
version="1.0.0",
docs_url="/swagger", # Change Swagger UI path
redoc_url="/redoc", # Change Redoc path
openapi_url="/openapi.json" # Change OpenAPI schema path
)
# CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:5173", "https://dataintel-hub-frontend.onrender.com"], # Allow frontend origin for local dev
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Security
security = HTTPBearer()
# Include routers
app.include_router(user_router, prefix="/api/users", tags=["users"])
app.include_router(report_router, prefix="/api/users", tags=["reports"])
# Root endpoint
@app.get("/")
async def root():
return {"message": "DataIntel Hub API is running!"}
# Health check endpoint
@app.get("/health")
async def health_check():
return {"status": "healthy", "service": "DataIntel Hub API"}
# Error handling
@app.exception_handler(Exception)
async def global_exception_handler(request, exc):
return error_handler(request, exc)
# Get port from environment variable or default to 8091
port = int(os.getenv("PORT", 8090))
if __name__ == "__main__":
uvicorn.run(
"main:app",
host="0.0.0.0",
port=port,
reload=True
)