Skip to content

Commit

Permalink
Fix frontend api request block due to mixed content (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-selo authored Oct 25, 2023
1 parent 599526f commit 5944c53
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
5 changes: 3 additions & 2 deletions backend/test_observer/controllers/application/version.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from importlib.metadata import version, PackageNotFoundError
from importlib.metadata import PackageNotFoundError, version

from fastapi import APIRouter

router = APIRouter()


@router.get("/")
@router.get("")
async def get_version():
try:
return {"version": version(__package__)}
Expand Down
2 changes: 1 addition & 1 deletion backend/test_observer/controllers/artefacts/artefacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
router = APIRouter()


@router.get("/", response_model=list[ArtefactDTO])
@router.get("", response_model=list[ArtefactDTO])
def get_artefacts(family: FamilyName | None = None, db: Session = Depends(get_db)):
"""Get latest artefacts by family"""
query = db.query(Stage)
Expand Down
15 changes: 10 additions & 5 deletions backend/test_observer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,25 @@

import os

import sentry_sdk
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import sentry_sdk


from test_observer.controllers.router import router


SENTRY_DSN = os.getenv("SENTRY_DSN")
if SENTRY_DSN:
sentry_sdk.init(SENTRY_DSN) # type: ignore


app = FastAPI()
app = FastAPI(
# Redirecting slashes can return a http schemed host when the request is https.
# A browser may block such a request means that the frontend loads without data.
# See https://developer.mozilla.org/en-US/docs/Web/Security/Mixed_content/How_to_fix_website_with_mixed_content
# By stopping redirects, the api will get a 404 if it doesn't use the exact path.
# This is useful to remind developers to use the exact path during development.
# To be a standard all paths should not end with a trailing slash.
redirect_slashes=False,
)

app.add_middleware(
CORSMiddleware,
Expand Down

0 comments on commit 5944c53

Please sign in to comment.