Как спрятать API_KEY?
Немогу спрятать ключ api которий получил в openweather, как ето сделать не используя node? Код JS:
const key = "мой ключ"
const target = document.querySelector(".weather__content--city")
const temp = document.querySelector(".weather__content--temp")
const icon = document.querySelector(".weather__content--icon")
const description = document.querySelector(".weather__content--description")
const humidity = document.querySelector(".weather__content--humidity")
const wind = document.querySelector(".weather__content--wind")
const input = document.querySelector(".weather__search--input")
const btn = document.querySelector(".weather__search--btn")
// get weather
function getWeather(city="Lviv") {
fetch("https://api.openweathermap.org/data/2.5/weather?q=" + city + "&units=metric&appid=" + key)
.then(response => {
return response.json()
}).then(data => {
showWeather(data)
})
}
// show weather data
function showWeather(data) {
const dName = data.name
const dIcon = data.weather[0].icon
const dDescription = data.weather[0].description
const dTemp = data.main.temp
const dHumidity = data.main.humidity
const dWind = data.wind.speed
target.innerHTML = dName
temp.innerHTML = Math.floor(dTemp) + "°C"
icon.src = "https://openweathermap.org/img/wn/" + dIcon + ".png"
description.innerHTML = dDescription
humidity.innerHTML = "Humidity: " + dHumidity + "%"
wind.innerHTML = "Wind speed: " + dWind + " km/h"
}
// search city
function searchCity() {
const value = input.value
getWeather(value)
}
// keyup event
input.addEventListener("keyup", function (e) {
if (e.key === "Enter") {
searchCity()
}
})
// click event
btn.addEventListener("click", searchCity)
getWeather()