-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathapp.py
More file actions
44 lines (29 loc) · 1.02 KB
/
app.py
File metadata and controls
44 lines (29 loc) · 1.02 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
from typing import Optional
from fastapi import FastAPI, status
from fastapi.responses import JSONResponse
from google.cloud.sqlcommenter.fastapi import (
SQLCommenterMiddleware, get_fastapi_info,
)
from starlette.applications import Starlette
from starlette.exceptions import HTTPException as StarletteHTTPException
from starlette.routing import Route
app = FastAPI(title="SQLCommenter")
app.add_middleware(SQLCommenterMiddleware)
@app.get("/fastapi-info")
def fastapi_info():
return get_fastapi_info()
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Optional[str] = None):
return get_fastapi_info()
@app.exception_handler(StarletteHTTPException)
async def custom_http_exception_handler(request, exc):
return JSONResponse(
status_code=status.HTTP_404_NOT_FOUND,
content=get_fastapi_info(),
)
def starlette_endpoint(_):
return JSONResponse({"from": "starlette"})
starlette_subapi = Starlette(routes=[
Route("/", starlette_endpoint),
])
app.mount("/starlette", starlette_subapi)