Skip to content

Commit

Permalink
Try to remove a couple of incidental changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dbutenhof committed Oct 7, 2024
1 parent 5671d77 commit a49fc65
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
53 changes: 27 additions & 26 deletions backend/app/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sys
import traceback
import typing

from fastapi import FastAPI, HTTPException, Request
Expand All @@ -17,23 +16,24 @@ def render(self, content: typing.Any) -> bytes:
return orjson.dumps(content)


origins = ["http://localhost:3000", "localhost:3000"]
origins = [
"http://localhost:3000",
"localhost:3000"
]

app = FastAPI(
default_response_class=ORJSONResponse,
docs_url="/docs",
redoc_url=None,
title="CPT-Dashboard API Documentation",
version="0.0.1",
contact={
"name": "OCP PerfScale Jedi",
"url": "https://redhat.enterprise.slack.com/archives/C05CDC19ZKJ",
},
license_info={
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0",
},
)
app = FastAPI(default_response_class=ORJSONResponse,
docs_url="/docs",
redoc_url=None,
title="CPT-Dashboard API Documentation",
version="0.0.1",
contact={
"name": "OCP PerfScale Jedi",
"url": "https://redhat.enterprise.slack.com/archives/C05CDC19ZKJ",
},
license_info={
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0",
})


@app.middleware("http")
Expand All @@ -53,7 +53,10 @@ async def report_exceptions(request: Request, call_next):
file=sys.stderr,
)
tb = tb.tb_next
return JSONResponse(status_code=500, content={"message": f"Unhandled server error at {where}: {str(e)}"})
return JSONResponse(
status_code=500,
content={"message": f"Unhandled server error at {where}: {str(e)}"},
)


app.add_middleware(
Expand All @@ -64,17 +67,15 @@ async def report_exceptions(request: Request, call_next):
allow_headers=["*"],
)

routes_to_reroute = ["/"]

routes_to_reroute = ['/']

@app.middleware("http")
@app.middleware('http')
async def some_middleware(request: Request, call_next):
if request.url.path in routes_to_reroute:
request.scope["path"] = "/docs"
headers = dict(request.scope["headers"])
headers[b"custom-header"] = b"my custom header"
request.scope["headers"] = [(k, v) for k, v in headers.items()]
request.scope['path'] = '/docs'
headers = dict(request.scope['headers'])
headers[b'custom-header'] = b'my custom header'
request.scope['headers'] = [(k, v) for k, v in headers.items()]
return await call_next(request)


app.include_router(router)
3 changes: 1 addition & 2 deletions backend/scripts/start-reload.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#!/usr/bin/bash
LOG=${CPT_BACKEND_LOG_LEVEL:-info}
uvicorn --reload --log-level="${LOG}" --host="0.0.0.0" --port=8000 --forwarded-allow-ips='*' --proxy-headers app.main:app
uvicorn --reload --host="0.0.0.0" --port=8000 --forwarded-allow-ips='*' --proxy-headers app.main:app

0 comments on commit a49fc65

Please sign in to comment.