<div class="weatherWidget">
{{#each partials.weatherContext}}
<div class="location">
<h3>{{location.name}}</h3>
<a href="{{location.forecastUrl}}">
<img src="{{iconUrl}}" alt="{{weather}}">
{{weather}}, {{temp}}
</a>
</div>
{{/each}}
<small>Source: <a href="https://www.weather.gov/documentation/services-web-api">
National Weather Service
</a> </small>
</div>
const getWeatherData = () => [
{
location: {
name: 'Portland',
coordinates: {lat: 45.5154586, lng: -122.6793461}
},
forecastUrl: 'https://api.weather.gov/gridpoints/PQR/112,103/forecast',
iconUrl: 'https://api.weather.gov/icons/land/day/tsra,40?size=medium',
weather: 'Chance Showers And Thunderstorms',
temp: '59 F',
},
{
location: {
name: 'Bend',
coordinates: {lat: 44.0581728, lng: -121.3153096}
},
forecastUrl: 'https://api.weather.gov/gridpoints/PQR/34,40/forecast',
iconUrl: 'https://api.weather.gov/icons/land/day/tsra_sct,50?size=medium',
weather: 'Scattered Showers And Thunderstorms',
temp: '51 F',
},
{
location: {
name: 'Manzanita',
coordinates: {lat: 45.7184398, lng: -123.9351354}
},
forecastUrl: 'https://api.weather.gov/gridpoints/PQR/73,120/forecast',
iconUrl: 'https://api.weather.gov/icons/land/day/tsra,90?size=medium',
weather: 'Chance Showers And Thunderstorms',
temp: '50 F',
},
]
const weatherMiddleware = async (req, res, next) => {
if(!res.locals.partials) res.locals.partials = {}
res.locals.partials.weatherContext = await getWeatherData()
next()
}
module.exports = weatherMiddleware
const weatherMiddleware = require('./lib/middleware/weather')
app.use(weatherMiddleware);
{{> 파일명}}
으로 파셜 파일을 가져올 수 있다.<h1>Welcome to Meadowlark Travel</h1>
<p>Questions? Checkout out our
<a href="/about" data-test-id="about">About Us</a></p>
{{> weather}}