Success
Home Hub Stories Hub NFC Store

Decrypting Story Data...

### 2. `api/story.js` (Cleaned Backend Code) ```javascript import fs from 'fs'; import path from 'path'; export default async function handler(req, res) { const { id } = req.query; const filePath = path.join(process.cwd(), 'post.html'); let html; try { html = fs.readFileSync(filePath, 'utf8'); } catch (e) { return res.status(500).send("Error: Template post.html not found."); } if (!id) { res.setHeader('Content-Type', 'text/html'); return res.status(200).send(html); } const SUPABASE_URL = "[https://lczljksnkambwrtusapx.supabase.co](https://lczljksnkambwrtusapx.supabase.co)"; const SUPABASE_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imxjemxqa3Nua2FtYndydHVzYXB4Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjY2NTc3ODEsImV4cCI6MjA4MjIzMzc4MX0.bt2WTdTtTYu40NaC884tRIfec4ycZrEdeisQ0MoFCqM"; try { const sbRes = await fetch(`${SUPABASE_URL}/rest/v1/stories?id=eq.${id}&select=*`, { headers: { "apikey": SUPABASE_KEY, "Authorization": `Bearer ${SUPABASE_KEY}` } }); const storyData = await sbRes.json(); if (storyData && storyData.length > 0) { const story = storyData[0]; let authorName = "Networker"; let authorHandle = "user"; if (story.user_id) { const authorRes = await fetch(`${SUPABASE_URL}/rest/v1/profiles?id=eq.${story.user_id}&select=full_name,username`, { headers: { "apikey": SUPABASE_KEY, "Authorization": `Bearer ${SUPABASE_KEY}` } }); const authorData = await authorRes.json(); if (authorData && authorData.length > 0) { authorName = authorData[0].full_name || authorName; authorHandle = authorData[0].username || authorHandle; } } const cleanContent = story.content ? story.content.replace(/(<([^>]+)>)/gi, "") : ""; const shortDesc = cleanContent.substring(0, 150) + '...'; const imageUrl = story.image_url || "[https://wecontact.app/default-og.jpg](https://wecontact.app/default-og.jpg)"; const title = `${story.title} – WeContact`; const currentUrl = `https://wecontact.app/story/${id}`; html = html.replace(/.*?<\/title>/i, `<title>${title}`); html = html.replace(//i, ``); html = html.replace(//i, ``); html = html.replace(//i, ``); html = html.replace(//i, ``); html = html.replace(//i, ``); const schemaData = { "@context": "[https://schema.org](https://schema.org)", "@type": "Article", "headline": story.title, "image": imageUrl, "datePublished": story.created_at, "author": { "@type": "Person", "name": authorName, "url": `https://wecontact.app/${authorHandle}` }, "publisher": { "@type": "Organization", "name": "WeContact", "logo": { "@type": "ImageObject", "url": "[https://wecontact.app/logo.png](https://wecontact.app/logo.png)" } } }; const schemaScript = `\n`; html = html.replace(/<\/head>/i, schemaScript); // Injects text exactly where the itemprop tag is html = html.replace( /(
]*>)/i, `$1\n${story.content}` ); } res.setHeader('Content-Type', 'text/html'); return res.status(200).send(html); } catch (error) { console.error("Vercel Serverless Error:", error); res.setHeader('Content-Type', 'text/html'); return res.status(200).send(html); } }