mirror of
https://github.com/dergigi/boris.git
synced 2025-12-18 23:24:22 +01:00
fix: use sentinel query param for OG redirect to preserve /a/:naddr paths
- Change OG HTML redirect to use ?_spa=1 query param instead of redirecting to / - Simplify vercel.json rewrites: serve SPA when _spa=1, otherwise serve OG HTML - Remove brittle user-agent detection patterns - Add cleanup effect to strip _spa param from URL after SPA loads - Fixes refresh redirect regression while maintaining OG preview support
This commit is contained in:
@@ -60,7 +60,7 @@ ${articleTags}
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<noscript>
|
<noscript>
|
||||||
<p>Redirecting to <a href="/">Boris</a>...</p>
|
<p>Redirecting to <a href="/a/${naddr}">Boris</a>...</p>
|
||||||
</noscript>
|
</noscript>
|
||||||
<script>
|
<script>
|
||||||
(function(){
|
(function(){
|
||||||
@@ -69,7 +69,8 @@ ${articleTags}
|
|||||||
if (window.location.pathname !== p) {
|
if (window.location.pathname !== p) {
|
||||||
history.replaceState(null, '', p);
|
history.replaceState(null, '', p);
|
||||||
}
|
}
|
||||||
window.location.replace('/');
|
var sep = window.location.search ? '&' : '?';
|
||||||
|
window.location.replace(p + sep + '_spa=1');
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
10
src/App.tsx
10
src/App.tsx
@@ -755,6 +755,16 @@ function App() {
|
|||||||
}
|
}
|
||||||
}, [showToast])
|
}, [showToast])
|
||||||
|
|
||||||
|
// Strip _spa query parameter from URL after SPA loads
|
||||||
|
useEffect(() => {
|
||||||
|
const url = new URL(window.location.href)
|
||||||
|
if (url.searchParams.has('_spa')) {
|
||||||
|
url.searchParams.delete('_spa')
|
||||||
|
const path = url.pathname + (url.search ? url.search : '') + url.hash
|
||||||
|
window.history.replaceState(null, '', path)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
if (!eventStore || !accountManager || !relayPool) {
|
if (!eventStore || !accountManager || !relayPool) {
|
||||||
return (
|
return (
|
||||||
<div className="loading">
|
<div className="loading">
|
||||||
|
|||||||
13
vercel.json
13
vercel.json
@@ -11,21 +11,14 @@
|
|||||||
"rewrites": [
|
"rewrites": [
|
||||||
{
|
{
|
||||||
"source": "/a/:naddr",
|
"source": "/a/:naddr",
|
||||||
"destination": "/api/article-og?naddr=:naddr",
|
"destination": "/index.html",
|
||||||
"has": [
|
"has": [
|
||||||
{ "type": "query", "key": "og", "value": "1" }
|
{ "type": "query", "key": "_spa", "value": "1" }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"source": "/a/:naddr",
|
"source": "/a/:naddr",
|
||||||
"destination": "/api/article-og?naddr=: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": "/(.*)",
|
"source": "/(.*)",
|
||||||
|
|||||||
Reference in New Issue
Block a user