fix dependency major version changes
This commit is contained in:
parent
d0509f14ae
commit
994b55530c
6
.vscode/launch.json
vendored
6
.vscode/launch.json
vendored
|
@ -36,5 +36,11 @@
|
||||||
"program": "${workspaceFolder}/index.js",
|
"program": "${workspaceFolder}/index.js",
|
||||||
"outputCapture": "std",
|
"outputCapture": "std",
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"compounds": [
|
||||||
|
{
|
||||||
|
"name": "Compound",
|
||||||
|
"configurations": ["Frontend", "Server"]
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -6,14 +6,12 @@ const https = require('https');
|
||||||
// url parsing
|
// url parsing
|
||||||
const queryString = require('querystring');
|
const queryString = require('querystring');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// return an express router
|
// return an express router
|
||||||
module.exports = (req, res) => {
|
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,16 +20,16 @@ module.exports = (req, res) => {
|
||||||
// add the paramter to the resulting object
|
// add the paramter to the resulting object
|
||||||
acc[key] = req.query[key];
|
acc[key] = req.query[key];
|
||||||
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://api.weather.gov' + req.path + query, {
|
https.get(`https://api.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
|
||||||
res.status(statusCode);
|
res.status(statusCode);
|
||||||
|
|
||||||
|
@ -39,8 +37,7 @@ module.exports = (req, res) => {
|
||||||
res.header('content-type', getRes.headers['content-type']);
|
res.header('content-type', getRes.headers['content-type']);
|
||||||
// pipe to response
|
// pipe to response
|
||||||
getRes.pipe(res);
|
getRes.pipe(res);
|
||||||
|
}).on('error', (e) => {
|
||||||
}).on('error', e=>{
|
|
||||||
console.error(e);
|
console.error(e);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,6 +24,7 @@ class CurrentWeather extends WeatherDisplay {
|
||||||
stationNum += 1;
|
stationNum += 1;
|
||||||
try {
|
try {
|
||||||
// station observations
|
// station observations
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
observations = await utils.fetch.json(`${station.id}/observations`, {
|
observations = await utils.fetch.json(`${station.id}/observations`, {
|
||||||
cors: true,
|
cors: true,
|
||||||
data: {
|
data: {
|
||||||
|
@ -38,8 +39,6 @@ class CurrentWeather extends WeatherDisplay {
|
||||||
observations = undefined;
|
observations = undefined;
|
||||||
throw new Error(`Unable to get observations: ${station.properties.stationIdentifier}, trying next station`);
|
throw new Error(`Unable to get observations: ${station.properties.stationIdentifier}, trying next station`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add retry for further stations if observations are unavailable
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,8 +152,9 @@ class Radar extends WeatherDisplay {
|
||||||
day,
|
day,
|
||||||
hour,
|
hour,
|
||||||
minute,
|
minute,
|
||||||
|
}, {
|
||||||
zone: 'UTC',
|
zone: 'UTC',
|
||||||
}).setZone();
|
});
|
||||||
} else {
|
} else {
|
||||||
time = DateTime.fromHTTP(response.headers.get('last-modified')).setZone();
|
time = DateTime.fromHTTP(response.headers.get('last-modified')).setZone();
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,8 +256,8 @@ const utils = (() => {
|
||||||
let corsUrl = _url;
|
let corsUrl = _url;
|
||||||
if (params.cors === true) corsUrl = rewriteUrl(_url);
|
if (params.cors === true) corsUrl = rewriteUrl(_url);
|
||||||
const url = new URL(corsUrl);
|
const url = new URL(corsUrl);
|
||||||
// force url to secure
|
// match the security protocol
|
||||||
url.protocol = 'https:';
|
url.protocol = window.location.protocol;
|
||||||
// add parameters if necessary
|
// add parameters if necessary
|
||||||
if (params.data) {
|
if (params.data) {
|
||||||
Object.keys(params.data).forEach((key) => {
|
Object.keys(params.data).forEach((key) => {
|
||||||
|
|
Loading…
Reference in a new issue