code cleanup

This commit is contained in:
Matt Walsh 2023-01-06 16:26:19 -06:00
parent b6e57e8a19
commit 339d391110
2 changed files with 16 additions and 18 deletions

View file

@ -11,7 +11,7 @@ module.exports = (req, res) => {
// add out-going headers // add out-going headers
const headers = {}; const headers = {};
headers['user-agent'] = '(WeatherStar 4000+, ws4000@netbymatt.com)'; headers['user-agent'] = '(WeatherStar 4000+, ws4000@netbymatt.com)';
headers['accept'] = req.headers.accept; headers.accept = req.headers.accept;
// get query paramaters if the exist // get query paramaters if the exist
const queryParams = Object.keys(req.query).reduce((acc, key) => { const queryParams = Object.keys(req.query).reduce((acc, key) => {
@ -22,12 +22,12 @@ module.exports = (req, res) => {
return acc; return acc;
}, {}); }, {});
let query = queryString.encode(queryParams); let query = queryString.encode(queryParams);
if (query.length > 0) query = '?' + query; if (query.length > 0) query = `?${query}`;
// get the page // get the page
https.get('https://www.cpc.ncep.noaa.gov/' + req.path + query, { https.get(`https://www.cpc.ncep.noaa.gov/${req.path}${query}`, {
headers, headers,
}, getRes => { }, (getRes) => {
// pull some info // pull some info
const { statusCode } = getRes; const { statusCode } = getRes;
// pass the status code through // pass the status code through
@ -38,8 +38,7 @@ module.exports = (req, res) => {
res.header('last-modified', getRes.headers['last-modified']); res.header('last-modified', getRes.headers['last-modified']);
// pipe to response // pipe to response
getRes.pipe(res); getRes.pipe(res);
}).on('error', (e) => {
}).on('error', e=>{
console.error(e); console.error(e);
}); });
}; };

View file

@ -11,7 +11,7 @@ module.exports = (req, res) => {
// add out-going headers // add out-going headers
const headers = {}; const headers = {};
headers['user-agent'] = '(WeatherStar 4000+, ws4000@netbymatt.com)'; headers['user-agent'] = '(WeatherStar 4000+, ws4000@netbymatt.com)';
headers['accept'] = req.headers.accept; headers.accept = req.headers.accept;
// get query paramaters if the exist // get query paramaters if the exist
const queryParams = Object.keys(req.query).reduce((acc, key) => { const queryParams = Object.keys(req.query).reduce((acc, key) => {
@ -22,12 +22,12 @@ module.exports = (req, res) => {
return acc; return acc;
}, {}); }, {});
let query = queryString.encode(queryParams); let query = queryString.encode(queryParams);
if (query.length > 0) query = '?' + query; if (query.length > 0) query = `?${query}`;
// get the page // get the page
https.get('https://radar.weather.gov' + req.path + query, { https.get(`https://radar.weather.gov${req.path}${query}`, {
headers, headers,
}, getRes => { }, (getRes) => {
// pull some info // pull some info
const { statusCode } = getRes; const { statusCode } = getRes;
// pass the status code through // pass the status code through
@ -38,8 +38,7 @@ module.exports = (req, res) => {
res.header('last-modified', getRes.headers['last-modified']); res.header('last-modified', getRes.headers['last-modified']);
// pipe to response // pipe to response
getRes.pipe(res); getRes.pipe(res);
}).on('error', (e) => {
}).on('error', e=>{
console.error(e); console.error(e);
}); });
}; };