2025-11-19 15:19:41 +03:00

22 lines
575 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { defineEventHandler, getQuery } from 'h3'
export default defineEventHandler(async (event) => {
try {
const { search } = getQuery(event)
const apiUrl = process.env.VITE_MY_API_BASE_URL!
return await $fetch<Posts>(`${apiUrl}/posts?title_like=${search}`, {
headers: {
'Content-Type': 'application/json',
'Accept-Language': 'ru-RU',
},
})
}
catch (error) {
return sendError(event, createError({
statusCode: 500,
statusMessage: `Не удалось получить посты: ${error}`,
}))
}
})