diff --git a/api/article-og.ts b/api/article-og.ts index 97ae71a6..a1617534 100644 --- a/api/article-og.ts +++ b/api/article-og.ts @@ -231,26 +231,38 @@ export default async function handler(req: VercelRequest, res: VercelResponse) { return res.status(200).json(debugInfo) } - // If it's a regular browser (not a bot), serve index.html with base tag - // The rewrite preserves the URL, so SPA routing will handle /a/{naddr} + // If it's a regular browser (not a bot), serve HTML that loads SPA + // Use history.replaceState to set the URL before the SPA boots if (!isCrawlerRequest) { - const fs = await import('fs') - const path = await import('path') - // eslint-disable-next-line no-undef - const indexPath = path.join(process.cwd(), 'dist', 'index.html') - - try { - let indexHtml = fs.readFileSync(indexPath, 'utf-8') - // Add base tag to ensure assets load from root - indexHtml = indexHtml.replace('', '\n ') - res.setHeader('Content-Type', 'text/html; charset=utf-8') - res.setHeader('Cache-Control', 'public, max-age=0, must-revalidate') - return res.status(200).send(indexHtml) - } catch (err) { - // Fallback if dist/index.html doesn't exist (dev mode) - res.setHeader('Location', '/') - return res.status(302).send('') + const articlePath = `/a/${naddr}` + // Serve a minimal HTML that sets up the URL and loads the SPA + const html = ` + + + + + + Boris - Loading Article... + + + + +
+ +` + + res.setHeader('Content-Type', 'text/html; charset=utf-8') + res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate') + return res.status(200).send(html) } // Check cache for bots/crawlers diff --git a/vercel.json b/vercel.json index 891d4ef1..f9c6977a 100644 --- a/vercel.json +++ b/vercel.json @@ -1,9 +1,5 @@ { "rewrites": [ - { - "source": "/a/:naddr", - "destination": "/api/article-og?naddr=:naddr" - }, { "source": "/(.*)", "destination": "/index.html"