mirror of
https://github.com/ArthurDanjou/arthome.git
synced 2026-01-14 20:19:26 +01:00
24 lines
660 B
TypeScript
24 lines
660 B
TypeScript
import type { OpenWeatherType } from '~~/types/types'
|
|
|
|
export default defineCachedEventHandler(async (event) => {
|
|
const config = useRuntimeConfig(event)
|
|
|
|
const openWeather = await $fetch<OpenWeatherType>('https://api.openweathermap.org/data/2.5/weather', {
|
|
params: {
|
|
lat: config.openWeather.lat,
|
|
lon: config.openWeather.lon,
|
|
appid: config.openWeather.apiKey,
|
|
lang: config.openWeather.lang,
|
|
units: config.openWeather.units,
|
|
},
|
|
})
|
|
return {
|
|
weather: openWeather.weather[0].description,
|
|
city: openWeather.name,
|
|
temp: openWeather.main.feels_like,
|
|
}
|
|
}, {
|
|
maxAge: 60 * 60, // 1 hour
|
|
name: 'weather',
|
|
})
|