Add missing GET /api/blog endpoint
cgen-2a66d3b40cfb464fa8871639d1133872
This commit is contained in:
parent
a89db320e0
commit
fdbfebb01d
1 changed files with 21 additions and 0 deletions
|
|
@ -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) => {
|
app.post("/api/blog", async (req, res) => {
|
||||||
const p = req.body || {};
|
const p = req.body || {};
|
||||||
const row = {
|
const row = {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue