Skip to content

Commit

Permalink
fix: cors, warmup pod increased mem
Browse files Browse the repository at this point in the history
  • Loading branch information
xgui3783 committed Apr 17, 2024
1 parent 15aa96b commit 09801b0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .helm/adhoc/warm-cache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
resources:
limits:
cpu: 900m
memory: 1Gi
memory: 4Gi
requests:
cpu: 500m
memory: 1Gi
Expand Down
45 changes: 23 additions & 22 deletions api/server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,6 @@
templates = Jinja2Templates(directory="templates/")
siibra_api.mount("/static", StaticFiles(directory="static"), name="static")

# Allow Cors

origins = ["*"]
siibra_api.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_methods=["GET"],
expose_headers=[siibra_version_header]
)

# some plugins may strip origin header for privacy reasons
# so if origin is unavailable, append it to trick corsmiddleware to activate
@siibra_api.middleware("http")
async def append_origin_header(request: Request, call_next):
headers = dict(request.scope["headers"])
origin = request.headers.get("origin")
new_headers = [(k, v) for k, v in headers.items()]
if not origin:
new_headers.append((b"origin", b"unknownorigin.dev"))
request.scope["headers"] = new_headers
return await call_next(request)

@siibra_api.get("/metrics", include_in_schema=False)
def get_metrics():
"""Get prometheus metrics"""
Expand Down Expand Up @@ -301,6 +279,29 @@ async def middleware_access_log(request: Request, call_next):
except Exception as e:
general_logger.critical(e)

# Allow Cors

origins = ["*"]
siibra_api.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_methods=["GET"],
expose_headers=[siibra_version_header]
)

# some plugins may strip origin header for privacy reasons
# so if origin is unavailable, append it to trick corsmiddleware to activate
@siibra_api.middleware("http")
async def append_origin_header(request: Request, call_next):
headers = dict(request.scope["headers"])
origin = request.headers.get("origin")
new_headers = [(k, v) for k, v in headers.items()]
if not origin:
new_headers.append((b"origin", b"unknownorigin.dev"))
request.scope["headers"] = new_headers
return await call_next(request)


@siibra_api.exception_handler(RuntimeError)
async def exception_runtime(request: Request, exc: RuntimeError) -> JSONResponse:
"""Handling RuntimeErrors.
Expand Down

0 comments on commit 09801b0

Please sign in to comment.