Implement dynamic SEO pre-rendering engine - #257
Conversation
Replace the static-generation pre-rendering strategy with a live, database-backed Dynamic Rendering Engine. Intercept public GET requests for catalogs, details, public logs, and user directories at the Nginx gateway, proxying them to a fast FastAPI endpoint. Pre-render page elements (metadata, breadcrumbs, JSON-LD schemas, and body content) into the DOM using the React SPA index.html skeleton, resolved dynamically and cached in memory. Specifically, pre-render catalogs, directories, and detail views for: - Dive Sites (`/dive-sites`) - Diving Centers (`/diving-centers`) - Dive Routes (`/dive-routes`) - Public logbooks (`/dives`, filtered for non-private entries) - User profiles, analytics, and custom lists (`/users`) - Dynamic calculators, certifications, and tags (`/resources`) - Static informational pages (`/about`, `/help`, `/privacy`) Configure a 10-minute Nginx proxy cache zone to handle search bot spikes without overloading the database. Cleanly handle HTTP 404 responses for deleted or missing entities, and revert the obsolete static pre-rendering generation and R2 Worker routing pipeline. Add a comprehensive integration test suite to verify route resolution, metadata correctness, caching, and custom 404 responses.
PR Reviewer Guide 🔍(Review updated until commit 784444c)Here are some key observations to aid the review process:
|
Mitigate security vulnerabilities and remove dead code from the SEO pre-rendering layer. Apply strict Host header validation in the dynamic HTML pre-render router to prevent Host Header Injection attacks. Untrusted production requests are forced to the canonical production domain. Wrap user-controlled strings (usernames, dive titles, and logged notes) with HTML escaping to eliminate Stored XSS risks on profiles and logs. Prune obsolete static HTML compiler helper functions to keep the pre-rendering codebase lightweight and free of orphaned dependencies.
|
/review |
|
Persistent review updated to latest commit 56230af |
Enhance security, optimize performance, and align canonical URL routing inside the SEO pre-rendering router. Validate usernames against an alphanumeric/dash regex format to prevent URL-encoded parsing exploits. Ensure list IDs are parsed as integers, returning a clean HTTP 404 for invalid, non-numeric collections. Implement HTTP 301 redirects on details pages when requested with a missing or mismatched slug, safely steering search engines to the true canonical URL and protecting against duplicate content indexing. Prune redundant SQLAlchemy joinedload options on catalog listing queries to reduce database join and memory overhead under bot crawling traffic. Add detailed test cases in the integration suite to verify redirect headers, username pattern restrictions, and non-numeric list limits.
|
/review |
|
Persistent review updated to latest commit 295d854 |
Add asyncio lock and filter out inactive accounts in SEO pre-render. Prevent a thundering herd on first-start template fetches by implementing an asyncio double-checked lock inside the loader. Filter out public dive logs and profile details associated with disabled, banned, or deleted user accounts, safeguarding privacy and preventing inactive content from appearing on search engines. Defensively escape numerical depth and duration metrics inside the pre-rendered dive detail template to protect against HTML injection.
|
/review |
|
Persistent review updated to latest commit 2df051c |
Avoid 'RuntimeError: Event loop is closed' warnings in tests by instantiating the template caching asyncio.Lock lazily inside the load function rather than at module import time. Isolate and secure URL parameters on user routes. Use raw validated usernames for canonical URLs and navigation hyperlinks to prevent HTML entity leakage, while keeping escaped variants strictly for display inside HTML tags. Add Nginx locations in both dev and prod configuration gateways to block external access to '/api/v1/seo/html', returning 403. This seals the pre-rendering route from external abuse and mitigates database-flooding risks.
|
/review |
|
Persistent review updated to latest commit 784444c |
Add explicit list length checks on resources sub-routes. Enforce strict index bounds checks on resource sub-path slices to prevent IndexError exceptions when parsing '/resources/tags' or any dynamic children under rare pathing edge cases. Confirm that catalog and database queries for public listings do not trigger any N+1 query patterns during active crawls. All relationship access is either restricted to direct columns or successfully pre-loaded via eager SQLAlchemy options.
Integrate styled navbar headers and brand colors into HTML. Style unstyled semantic HTML elements inside pre-rendered pages to bypass Tailwind's Preflight CSS reset defaults. Inject custom CSS rules to provide bold typography and card listings. Pre-render a fixed, styled top navigation header matching the real React app's '#0072b2' ocean-blue theme, complete with logo, mock search box, nav links, and authorization button skeletons. Render a high-contrast hero section on the homepage and structured card layouts on detail pages inside '<div id="root">'. This guarantees a seamless, pixel-perfect visual match and zero-layout-shift hydration when React boots.
Replace the static-generation pre-rendering strategy with a live, database-backed Dynamic Rendering Engine.
Intercept public GET requests for catalogs, details, public logs, and user directories at the Nginx gateway, proxying them to a fast FastAPI endpoint. Pre-render page elements (metadata, breadcrumbs, JSON-LD schemas, and body content) into the DOM using the React SPA index.html skeleton, resolved dynamically and cached in memory.
Specifically, pre-render catalogs, directories, and detail views for:
/dive-sites)/diving-centers)/dive-routes)/dives, filtered for non-private entries)/users)/resources)/about,/help,/privacy)Configure a 10-minute Nginx proxy cache zone to handle search bot spikes without overloading the database. Cleanly handle HTTP 404 responses for deleted or missing entities
Add a comprehensive integration test suite to verify route resolution, metadata correctness, caching, and custom 404 responses.