Take portfolio offline with blank pages and blocked API routes
This commit is contained in:
+16
-1
@@ -61,7 +61,10 @@ app = FastAPI(
|
||||
title="Alex Herlan Portfolio API",
|
||||
description="Supabase-ready content and contact delivery for Alex Herlan's portfolio.",
|
||||
version="1.1.0",
|
||||
lifespan=media_cleanup.lifespan,
|
||||
# The website is offline; do not start background storage cleanup.
|
||||
docs_url=None,
|
||||
redoc_url=None,
|
||||
openapi_url=None,
|
||||
)
|
||||
|
||||
origins = [
|
||||
@@ -78,6 +81,18 @@ app.add_middleware(
|
||||
)
|
||||
|
||||
|
||||
@app.middleware("http")
|
||||
async def site_offline(request: Request, call_next) -> Response:
|
||||
"""Keep every page, API, and file unavailable without deleting stored data."""
|
||||
return Response(
|
||||
# A minimal document avoids the browser's built-in error screen.
|
||||
content="<!doctype html><html><head><title></title></head><body></body></html>",
|
||||
status_code=410,
|
||||
media_type="text/html",
|
||||
headers={"Cache-Control": "no-store", "X-Robots-Tag": "noindex, nofollow"},
|
||||
)
|
||||
|
||||
|
||||
class ContactPayload(BaseModel):
|
||||
name: str = Field(min_length=2, max_length=100)
|
||||
email: EmailStr
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
"""Verify the intentional shutdown blocks content and storage side effects."""
|
||||
import json
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from backend import main
|
||||
|
||||
|
||||
class OfflineTests(unittest.TestCase):
|
||||
def test_all_routes_and_methods_return_blank_gone(self):
|
||||
paths = [
|
||||
"/", "/experience", "/blog/example", "/api/profile",
|
||||
"/api/experience", "/api/posts", "/api/health", "/api/resume",
|
||||
"/api/auth/login", "/api/contact", "/api/cron/media-cleanup",
|
||||
"/api/resume?v=resume-v25", "/resumes/resume-v25.pdf",
|
||||
"/api/uploads/" + "a" * 32, "/alexander-herlan.png",
|
||||
"/assets/old.js", "/docs", "/openapi.json", "/missing",
|
||||
]
|
||||
with patch.object(main, "get_supabase") as storage, \
|
||||
patch.object(main, "read_data") as data, \
|
||||
patch.object(main, "deliver_contact_email") as email, \
|
||||
patch.object(main.media_cleanup, "cleanup_pending") as cleanup, \
|
||||
TestClient(main.app) as client:
|
||||
for method in ("GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"):
|
||||
for path in paths:
|
||||
with self.subTest(method=method, path=path):
|
||||
response = client.request(method, path)
|
||||
self.assertEqual(response.status_code, 410)
|
||||
expected = b"<!doctype html><html><head><title></title></head><body></body></html>"
|
||||
self.assertEqual(response.content, b"" if method == "HEAD" else expected)
|
||||
self.assertEqual(response.headers["cache-control"], "no-store")
|
||||
self.assertEqual(response.headers["x-robots-tag"], "noindex, nofollow")
|
||||
storage.assert_not_called()
|
||||
data.assert_not_called()
|
||||
email.assert_not_called()
|
||||
cleanup.assert_not_called()
|
||||
|
||||
def test_vercel_has_no_static_bypass_or_scheduled_jobs(self):
|
||||
config = json.loads((main.PROJECT_DIR / "vercel.json").read_text(encoding="utf-8"))
|
||||
self.assertEqual(config["routes"], [{"src": "/.*", "dest": "/api/index.py"}])
|
||||
self.assertEqual(config["crons"], [])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user