paxton-front/server/api/yandex_location.ts
alsaze 2984e3780a
All checks were successful
Deploy / build (push) Successful in 11m3s
карты пвз
2025-11-19 21:12:47 +03:00

31 lines
835 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 axios from 'axios'
import { defineEventHandler, readBody } from 'h3'
export default defineEventHandler(async (event) => {
try {
const data = await readBody(event)
const apiUrl = import.meta.env.VITE_YANDEX_B2B_BASE_URL!
const token = import.meta.env.VITE_YANDEX_B2B_TOKEN!
const response = await axios.post(
`${apiUrl}/location/detect`,
{
location: data?.location,
},
{
headers: {
'Content-Type': 'application/json',
'Accept-Language': 'ru-RU',
'Authorization': `Bearer ${token}`,
},
},
)
return response.data
}
catch (error) {
console.error('Ошибка при запросе к Яндекс API:', error)
return { error: `Не удалось получить координаты: ${error}` }
}
})