mirror of
https://github.com/ArthurDanjou/arthome.git
synced 2026-01-14 12:14:33 +01:00
Add weather and map
This commit is contained in:
25
server/api/weather.get.ts
Normal file
25
server/api/weather.get.ts
Normal 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',
|
||||
})
|
||||
Reference in New Issue
Block a user