This commit is contained in:
30
server/api/yandex_location.ts
Normal file
30
server/api/yandex_location.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import axios from 'axios'
|
||||
import { defineEventHandler, readBody } from 'h3'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
const data = await readBody(event)
|
||||
const apiUrl = process.env.VITE_YANDEX_B2B_BASE_URL!
|
||||
const token = process.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}` }
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user