forked from microsoft/github-copilot-vibe-coding-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
35 lines (28 loc) · 1.03 KB
/
Copy pathmain.py
File metadata and controls
35 lines (28 loc) · 1.03 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
from fastapi import FastAPI, Request, Response, status
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse, FileResponse
from fastapi.openapi.docs import get_swagger_ui_html
import os
app = FastAPI(docs_url=None, redoc_url=None, openapi_url=None)
# Allow CORS from everywhere
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
OPENAPI_YAML_PATH = os.path.join(os.path.dirname(__file__), "../openapi.yaml")
@app.get("/", include_in_schema=False)
def swagger_ui_html():
return get_swagger_ui_html(
openapi_url="/openapi.yaml",
title="Simple Social Media Application API"
)
@app.get("/openapi.yaml", include_in_schema=False)
def serve_openapi_yaml():
return FileResponse(OPENAPI_YAML_PATH, media_type="application/yaml")
# ...endpoint implementations will be added here...
if __name__ == "__main__":
import uvicorn
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)