const axiosJWT = axios.create()
axiosJWT.interceptors.response.use((config) => {
return config;
}, async (error) => {
const originalRequest = error.config;
if (error.response.status === 401 && error.config && !error.config._isRetry) {
originalRequest._isRetry = true;
try {
await axios.post("http://localhost:5000/api/auth/refresh", {}, {withCredentials: true, headers: ctx.req ? {cookie: ctx.req.cookie} : undefined})
return axios.request(originalRequest);
} catch (e) {
console.log(e)
}
}
throw error;
});
const res = await axiosJWT.get("http://localhost:5000/api/auth", {
withCredentials: true,
headers: ctx.req ? { cookie: ctx.req.headers.cookie } : undefined
});
function fetchData() {
fetch(`https://api.openweathermap.org/data/2.5/weather?q=${city}&lang=ru&appid=${apiKey}`)
.then(function (resp) {
return resp.json();
})
.then(function (data) {
let cityName = document.querySelector(".City").innerHTML = data.name ;
let temperature = (document.querySelector(".temperature").innerHTML = Math.floor(data.main.temp - 273) + "°");
let disclaimer = (document.querySelector(".disclaimer").textContent = data.weather[0]["description"]);
let ico = (document.querySelector(".ico").innerHTML = `<img src="https://openweathermap.org/img/wn/${data.weather[0]["icon"]}@2x.png">`);
console.log (data)
})
.catch(function () {});
}
inputName.addEventListener('input', () => {
valueGet();
fetchData();
});