-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
62 lines (53 loc) · 1.66 KB
/
main.py
File metadata and controls
62 lines (53 loc) · 1.66 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
"""
Main application entry point for the Sensor Data GraphQL API.
"""
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from strawberry.fastapi import GraphQLRouter
from app.core.config import settings
from app.graphql.schema import schema
from app.database.database import engine, Base
from app.database import models
from app.api.endpoints.health import router as health_router
# Create database tables
Base.metadata.create_all(bind=engine)
# Create FastAPI application
app = FastAPI(
title=settings.APP_NAME,
version=settings.APP_VERSION,
debug=settings.DEBUG,
)
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Configure appropriately for production
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Create GraphQL router
graphql_app = GraphQLRouter(schema)
# Include GraphQL endpoint
app.include_router(graphql_app, prefix="/graphql")
# Include health and database management endpoints
app.include_router(health_router, prefix="/api/v1", tags=["health", "database"])
@app.get("/")
async def root():
"""Root endpoint returning API information."""
return {
"message": f"Welcome to {settings.APP_NAME}",
"version": settings.APP_VERSION,
"graphql_endpoint": "/graphql",
"database_info_endpoint": "/api/v1/database/info",
"health_endpoint": "/api/v1/health",
"environment": settings.ENVIRONMENT,
"database_provider": settings.DATABASE_PROVIDER,
}
if __name__ == "__main__":
import uvicorn
uvicorn.run(
"main:app",
host="0.0.0.0",
port=8000,
reload=settings.DEBUG,
)