-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.py
More file actions
75 lines (65 loc) · 2.08 KB
/
Copy pathindex.py
File metadata and controls
75 lines (65 loc) · 2.08 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
71
72
73
74
75
# api/index.py - Main FastAPI application entry point
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import os
from dotenv import load_dotenv
# Load environment variables (support .env.local and .env)
# .env.local is preferred for developer machines; .env for general defaults.
load_dotenv(dotenv_path=os.path.join(os.path.dirname(__file__), ".env.local"), override=False)
load_dotenv(dotenv_path=os.path.join(os.path.dirname(__file__), ".env"), override=False)
# Import route handlers (after env vars are loaded so sub-apps read them)
from app.events import app as events_app
from app.health import app as health_app
from app.media import app as media_app
# Create main app
app = FastAPI(
title="Embedded Purdue API",
description="API for managing events and media for Embedded Systems club",
version="1.0.0",
)
# Configure CORS
ALLOWED_ORIGIN = os.environ.get("ALLOWED_ORIGIN", "*")
origins = [ALLOWED_ORIGIN] if ALLOWED_ORIGIN != "*" else ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include routers from sub-apps
for route in events_app.routes:
app.routes.append(route)
for route in health_app.routes:
app.routes.append(route)
for route in media_app.routes:
app.routes.append(route)
# Root endpoint
@app.get("/")
async def root():
return {
"name": "Embedded Purdue API",
"version": "1.0.0",
"endpoints": {
"events": "/api/events",
"media": "/api/media",
"health": "/api/health",
}
}
@app.get("/api")
async def api_root():
return {
"endpoints": {
"events": {
"list": "GET /api/events",
"create": "POST /api/events",
},
"media": {
"list": "GET /api/media",
"create": "POST /api/media",
"upload": "POST /api/media/upload",
"upload_gh": "POST /api/media/upload-gh",
},
"health": "GET /api/health",
}
}