20 lines
619 B
JavaScript
20 lines
619 B
JavaScript
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 }
|
|
);
|
|
}
|
|
}
|