Add missing GET /api/blog endpoint

cgen-2a66d3b40cfb464fa8871639d1133872
This commit is contained in:
Builder.io 2025-11-10 03:51:51 +00:00
parent a89db320e0
commit fdbfebb01d

View file

@ -2378,6 +2378,27 @@ export function createServer() {
}
});
app.get("/api/blog", async (req, res) => {
const limit = Math.min(Number(req.query.limit) || 50, 200);
try {
const { data, error } = await adminSupabase
.from("blog_posts")
.select("*")
.order("published_at", { ascending: false })
.limit(limit);
if (error) {
// Table might not exist yet, return empty array
if (error.message?.includes("does not exist")) {
return res.json([]);
}
return res.status(500).json({ error: error.message });
}
res.json(data || []);
} catch (e: any) {
res.status(500).json({ error: e?.message || String(e) });
}
});
app.post("/api/blog", async (req, res) => {
const p = req.body || {};
const row = {