weather icons
This commit is contained in:
@@ -496,3 +496,24 @@ router.get('/conditions/suitable/:propertyId', async (req, res, next) => {
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
// Icon proxy to avoid external CSP/mixed-content issues
|
||||
// @route GET /api/weather/icon/:code
|
||||
// @desc Proxy OpenWeather icon by code (e.g., 10d) with optional size=2x
|
||||
// @access Public (icons only)
|
||||
router.get('/icon/:code', async (req, res, next) => {
|
||||
try {
|
||||
const { code } = req.params;
|
||||
const size = (req.query.size === '2x') ? '@2x' : '';
|
||||
if (!code || !/^[0-9]{2}[dn]$/.test(code)) {
|
||||
return res.status(400).send('invalid icon code');
|
||||
}
|
||||
const url = `https://openweathermap.org/img/wn/${code}${size}.png`;
|
||||
const response = await require('axios').get(url, { responseType: 'arraybuffer', timeout: 5000 });
|
||||
res.set('Content-Type', 'image/png');
|
||||
res.set('Cache-Control', 'public, max-age=21600'); // 6 hours
|
||||
return res.status(200).send(Buffer.from(response.data));
|
||||
} catch (error) {
|
||||
return res.status(502).send('icon fetch failed');
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user