From 0d9e9042ee827aeb506d60ea3d0e1915961e2723 Mon Sep 17 00:00:00 2001 From: Andrew Njoo Date: Wed, 29 May 2024 09:24:05 -0700 Subject: [PATCH] blog api --- src/app/(api)/api/blog/route.ts | 14 ++++++++++++++ src/app/(api)/{ => api}/soundcloud/route.ts | 0 src/components/Songs.tsx | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/app/(api)/api/blog/route.ts rename src/app/(api)/{ => api}/soundcloud/route.ts (100%) diff --git a/src/app/(api)/api/blog/route.ts b/src/app/(api)/api/blog/route.ts new file mode 100644 index 0000000..4c3a641 --- /dev/null +++ b/src/app/(api)/api/blog/route.ts @@ -0,0 +1,14 @@ +import { NextResponse } from 'next/server'; +import { getPosts } from '@/app/blog/functions'; + +export async function GET() { + const posts = await getPosts(); + const count = posts.length; + + return NextResponse.json({ + meta: { + count, + }, + posts, + }); +} diff --git a/src/app/(api)/soundcloud/route.ts b/src/app/(api)/api/soundcloud/route.ts similarity index 100% rename from src/app/(api)/soundcloud/route.ts rename to src/app/(api)/api/soundcloud/route.ts diff --git a/src/components/Songs.tsx b/src/components/Songs.tsx index 58049d9..3e0d094 100644 --- a/src/components/Songs.tsx +++ b/src/components/Songs.tsx @@ -2,7 +2,7 @@ import Link from 'next/link'; async function getLikedSongs() { try { - const response = await fetch(process.env.URL + '/soundcloud', { + const response = await fetch(process.env.URL + '/api/soundcloud', { cache: 'no-store', }); const data = await response.json();