Files
sori.studio/server/api/search.get.js

13 lines
606 B
JavaScript

import { searchPublicContent } from '../repositories/content-repository'
/**
* 공개 통합 검색 API(태그·게시물·페이지)
* @param {import('h3').H3Event} event - 요청 이벤트
* @returns {Promise<{ tags: Array<{ name: string, slug: string }>, posts: Array<{ slug: string, title: string, excerpt: string }>, pages: Array<{ slug: string, title: string, excerpt: string }> }>} 검색 결과
*/
export default defineEventHandler(async (event) => {
const raw = getQuery(event).q
const q = Array.isArray(raw) ? raw[0] : raw
return searchPublicContent(typeof q === 'string' ? q : '')
})