Мой сайт сломался между прошлой и прошлой ночью, хотя я ничего не менял. Я делаю сайт, который собирает данные о погоде. Это основано непосредственно на средней статье здесь: https://codeburst.io/build-a-weather-website-in-30-minutes-with-node-js-express-openweather-a317f904897b
Вот содержимое сервера js ...
app.post('/', function (req, res) {
let city = req.body.city;
let country = req.body.country;
let url = `http://api.openweathermap.org/data/2.5/weather?q=${city}${
country.length > 0 ? "," + country : ""
}&units=imperial&appid=${api}`
request(url, function(err, response, body){
if (err) {
res.render('index',
{weather: null, error: "Please Enter Valid Location"});
}
else {
let weather = JSON.parse(body)
if (weather.main == undefined) {
res.render('index',
{weather: null, error: "Please Enter Valid Location"});
}
else {
let content = {
temp: weather.main.temp,
city: weather.name,
condition: weather.weather[0].description,
icon: "svgs/" + weather.weather[0].icon + ".svg"
}
res.render('index', {weather: content, error: null});
}
}
})
});
А вот и соответствующие шаблоны EJS ...
<% if (locals.weather !== null){ %>
<p><%= locals.weather.city %></p>
<p><%= locals.weather.condition %></p>
<% } %>
<% if(error !== null){ %>
<p><%= error %></p>
<% } %>
Это сработало прошлой ночью, но теперь оно говорит: «Невозможно прочитать свойство 'city' undefined".