astro_hts/frontend/src/pages/api/search.json.ts
2026-03-26 04:55:25 +05:00

21 lines
582 B
TypeScript

import type { APIRoute } from "astro";
import { getCollection } from "astro:content";
import type { CollectionEntry } from "astro:content";
export const GET: APIRoute = async (): Promise<Response> => {
const allPosts: CollectionEntry<"post">[] = await getCollection("post");
const searchData = allPosts.map((post) => ({
id: post.id,
title: post.data.title,
description: post.data.description,
body: post.body,
}));
return new Response(JSON.stringify(searchData), {
status: 200,
headers: {
"Content-Type": "application/json",
},
});
};