From 0bfa0a2e7b3940203f2f1eebdc40299c0948e867 Mon Sep 17 00:00:00 2001 From: Gigi Date: Fri, 7 Nov 2025 23:00:12 +0100 Subject: [PATCH] fix: gate /a/:naddr rewrite to crawlers to prevent refresh redirect - Add conditional rewrite rules in vercel.json to only serve OG HTML to crawlers - Add ?og=1 query parameter override for manual testing - Document ?og=1 testing path in README - Fixes regression where browser refresh on /a/:naddr redirected to root --- README.md | 12 ++++++++++++ vercel.json | 16 +++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8ce07c53..573d6636 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,18 @@ If you bookmark something on nostr, Boris will show it in the bookmarks bar. If - If something looks empty, try opening another article and coming back — network data can arrive in bursts. - Not every article has highlights yet; they grow as the community reads. +## Development + +### Testing Open Graph Previews + +To manually test the Open Graph HTML preview for an article, append `?og=1` to any `/a/:naddr` URL: + +```text +https://read.withboris.com/a/?og=1 +``` + +This bypasses the normal SPA routing and serves the OG preview HTML directly, useful for verifying social media preview cards. + ## License MIT diff --git a/vercel.json b/vercel.json index fb4b78a1..30b864a1 100644 --- a/vercel.json +++ b/vercel.json @@ -11,7 +11,21 @@ "rewrites": [ { "source": "/a/:naddr", - "destination": "/api/article-og?naddr=:naddr" + "destination": "/api/article-og?naddr=:naddr", + "has": [ + { "type": "query", "key": "og", "value": "1" } + ] + }, + { + "source": "/a/:naddr", + "destination": "/api/article-og?naddr=:naddr", + "has": [ + { + "type": "header", + "key": "user-agent", + "value": ".*(bot|Bot|BOT|crawler|Crawler|CRAWLER|spider|Spider|facebookexternalhit|Slackbot|Twitterbot|LinkedInBot|WhatsApp|TelegramBot|Discordbot|Googlebot|bingbot|YandexBot|Baiduspider).*" + } + ] }, { "source": "/(.*)",