Add weather and map

This commit is contained in:
2024-08-22 22:42:02 +02:00
parent 331f8bd3ce
commit 324aa143d1
18 changed files with 905 additions and 59 deletions

25
server/api/weather.get.ts Normal file
View File

@@ -0,0 +1,25 @@
import type { OpenWeatherType } from '~~/types/types'
export default defineCachedEventHandler(async (event) => {
const config = useRuntimeConfig(event)
console.log(config.openWeather)
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,
},
})
console.log(openWeather)
return {
weather: openWeather.weather[0].description,
city: openWeather.name,
temp: openWeather.main.feels_like,
}
}, {
maxAge: 60 * 60, // 1 hour
name: 'weather',
})