diff --git a/.vscode/launch.json b/.vscode/launch.json index 0725980..0697965 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -36,5 +36,11 @@ "program": "${workspaceFolder}/index.js", "outputCapture": "std", } + ], + "compounds": [ + { + "name": "Compound", + "configurations": ["Frontend", "Server"] + } ] } \ No newline at end of file diff --git a/cors/index.js b/cors/index.js index ca12788..e964565 100644 --- a/cors/index.js +++ b/cors/index.js @@ -6,14 +6,12 @@ const https = require('https'); // url parsing const queryString = require('querystring'); - - // return an express router module.exports = (req, res) => { // add out-going headers const headers = {}; headers['user-agent'] = '(WeatherStar 4000+, ws4000@netbymatt.com)'; - headers['accept'] = req.headers.accept; + headers.accept = req.headers.accept; // get query paramaters if the exist const queryParams = Object.keys(req.query).reduce((acc, key) => { @@ -22,16 +20,16 @@ module.exports = (req, res) => { // add the paramter to the resulting object acc[key] = req.query[key]; return acc; - },{}); + }, {}); let query = queryString.encode(queryParams); - if (query.length > 0) query = '?' + query; + if (query.length > 0) query = `?${query}`; // get the page - https.get('https://api.weather.gov' + req.path + query, { + https.get(`https://api.weather.gov${req.path}${query}`, { headers, - }, getRes => { + }, (getRes) => { // pull some info - const {statusCode} = getRes; + const { statusCode } = getRes; // pass the status code through res.status(statusCode); @@ -39,8 +37,7 @@ module.exports = (req, res) => { res.header('content-type', getRes.headers['content-type']); // pipe to response getRes.pipe(res); - - }).on('error', e=>{ + }).on('error', (e) => { console.error(e); }); -}; \ No newline at end of file +}; diff --git a/server/scripts/modules/currentweather.js b/server/scripts/modules/currentweather.js index 02721c1..b47351e 100644 --- a/server/scripts/modules/currentweather.js +++ b/server/scripts/modules/currentweather.js @@ -24,6 +24,7 @@ class CurrentWeather extends WeatherDisplay { stationNum += 1; try { // station observations + // eslint-disable-next-line no-await-in-loop observations = await utils.fetch.json(`${station.id}/observations`, { cors: true, data: { @@ -38,8 +39,6 @@ class CurrentWeather extends WeatherDisplay { observations = undefined; 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) { console.error(e); } diff --git a/server/scripts/modules/radar.js b/server/scripts/modules/radar.js index 94b8c25..38565c9 100644 --- a/server/scripts/modules/radar.js +++ b/server/scripts/modules/radar.js @@ -152,8 +152,9 @@ class Radar extends WeatherDisplay { day, hour, minute, + }, { zone: 'UTC', - }).setZone(); + }); } else { time = DateTime.fromHTTP(response.headers.get('last-modified')).setZone(); } diff --git a/server/scripts/modules/utilities.js b/server/scripts/modules/utilities.js index 6bfc35d..2a1ede2 100644 --- a/server/scripts/modules/utilities.js +++ b/server/scripts/modules/utilities.js @@ -256,8 +256,8 @@ const utils = (() => { let corsUrl = _url; if (params.cors === true) corsUrl = rewriteUrl(_url); const url = new URL(corsUrl); - // force url to secure - url.protocol = 'https:'; + // match the security protocol + url.protocol = window.location.protocol; // add parameters if necessary if (params.data) { Object.keys(params.data).forEach((key) => {