Skip to content

Commit

Permalink
Replaced HTTP redirect on / to HTML redirect
Browse files Browse the repository at this point in the history
Apple Pay Verification system seems unhappy with redirects on / when
it is verifying domain.

This ought to keep it happy while maintaining the feature for end users
  • Loading branch information
rgaudin committed Feb 6, 2025
1 parent 758dc74 commit 715dbd5
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions donation-api/src/donation_api/entrypoint.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from http import HTTPStatus

from fastapi import FastAPI
from fastapi import FastAPI, Response
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import PlainTextResponse, RedirectResponse
from fastapi.responses import PlainTextResponse

from donation_api import stripe
from donation_api.__about__ import __description__, __title__, __version__
Expand All @@ -19,9 +19,26 @@ def create_app() -> FastAPI:
)

@app.get("/")
@app.head("/")
async def _():
"""Redirect to root of latest version of the API"""
return RedirectResponse(f"{PREFIX}/", status_code=HTTPStatus.PERMANENT_REDIRECT)
"""HTML Redirect to root of latest version of the API
Purposedly not an HTTP redirect as Apple Pay verification system
doesnt like it (apparently)"""

return Response(
f"""<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="refresh" content="0; url={PREFIX}/" />
<title>Donation API</title>
</head>
<body>
<p>Current version is located at <a href="{PREFIX}/">{PREFIX}/</a></p>
</body>
</html>"""
)

# could be done on infra ; this is a handy shortcut
if conf.merchantid_domain_association:
Expand Down

0 comments on commit 715dbd5

Please sign in to comment.