feat: make blog data dynamic

This commit is contained in:
2025-04-12 13:10:38 +05:30
parent ef61d38753
commit 72cd1a7f47
8 changed files with 370 additions and 181 deletions

View File

@@ -0,0 +1,19 @@
import { NextResponse } from "next/server";
import axios from "axios";
import { backendUrl } from "@/utils/axios";
export async function GET(request, { params }) {
const { slug } = params;
try {
console.log(`API route fetching blog with slug: ${slug}`);
const response = await axios.get(`${backendUrl}/blogs/${slug}/`);
return NextResponse.json(response.data);
} catch (error) {
console.error(`Error fetching blog with slug ${slug}:`, error);
return NextResponse.json(
{ error: `Failed to fetch blog: ${error.message}` },
{ status: error.response?.status || 500 }
);
}
}