From 1609ab3d388e81e7957f9d7cd0c7a778ab63eac0 Mon Sep 17 00:00:00 2001 From: Matt Walsh Date: Fri, 23 May 2025 22:14:48 -0500 Subject: [PATCH] radar host overrides --- .eslintrc | 3 ++- gulp/publish-frontend.mjs | 4 +++- index.mjs | 2 ++ server/scripts/modules/radar.mjs | 6 ++++-- src/overrides.mjs | 10 ++++++++++ views/index.ejs | 5 ++++- 6 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 src/overrides.mjs diff --git a/.eslintrc b/.eslintrc index 90c8555..f468c66 100644 --- a/.eslintrc +++ b/.eslintrc @@ -12,7 +12,8 @@ "RegionalCities": "readonly", "StationInfo": "readonly", "SunCalc": "readonly", - "NoSleep": "readonly" + "NoSleep": "readonly", + "OVERRIDES": "readonly" }, "parserOptions": { "ecmaVersion": "latest", diff --git a/gulp/publish-frontend.mjs b/gulp/publish-frontend.mjs index 044ae81..0dbc0eb 100644 --- a/gulp/publish-frontend.mjs +++ b/gulp/publish-frontend.mjs @@ -14,9 +14,10 @@ import webpack from 'webpack-stream'; import TerserPlugin from 'terser-webpack-plugin'; import { readFile } from 'fs/promises'; import file from 'gulp-file'; +import { CloudFrontClient, CreateInvalidationCommand } from '@aws-sdk/client-cloudfront'; +import OVERRIDES from '../src/overrides.mjs'; // get cloudfront -import { CloudFrontClient, CreateInvalidationCommand } from '@aws-sdk/client-cloudfront'; import reader from '../src/playlist-reader.mjs'; const clean = () => deleteAsync(['./dist/**/*', '!./dist/readme.txt']); @@ -113,6 +114,7 @@ const compressHtml = async () => { .pipe(ejs({ production: version, version, + OVERRIDES, })) .pipe(rename({ extname: '.html' })) .pipe(htmlmin({ collapseWhitespace: true })) diff --git a/index.mjs b/index.mjs index 40c3a7c..4ca315e 100644 --- a/index.mjs +++ b/index.mjs @@ -5,6 +5,7 @@ import corsPassThru from './cors/index.mjs'; import radarPassThru from './cors/radar.mjs'; import outlookPassThru from './cors/outlook.mjs'; import playlist from './src/playlist.mjs'; +import OVERRIDES from './src/overrides.mjs'; const app = express(); const port = process.env.WS4KP_PORT ?? 8080; @@ -57,6 +58,7 @@ const index = (req, res) => { res.render('index', { production: false, version, + OVERRIDES, }); }; diff --git a/server/scripts/modules/radar.mjs b/server/scripts/modules/radar.mjs index f8fb61a..dda0e53 100644 --- a/server/scripts/modules/radar.mjs +++ b/server/scripts/modules/radar.mjs @@ -8,6 +8,7 @@ import WeatherDisplay from './weatherdisplay.mjs'; import { registerDisplay, timeZone } from './navigation.mjs'; import * as utils from './radar-utils.mjs'; +const RADAR_HOST = 'mesonet.agron.iastate.edu'; class Radar extends WeatherDisplay { constructor(navId, elemId) { super(navId, elemId, 'Local Radar', true); @@ -55,7 +56,7 @@ class Radar extends WeatherDisplay { const src = 'images/maps/radar.webp'; this.baseMap = await loadImg(src); - const baseUrl = 'https://mesonet.agron.iastate.edu/archive/data/'; + const baseUrl = `https://${RADAR_HOST}/archive/data/`; const baseUrlEnd = '/GIS/uscomp/?F=0&P=n0r*.png'; const baseUrls = []; let date = DateTime.utc().minus({ days: 1 }).startOf('day'); @@ -134,7 +135,8 @@ class Radar extends WeatherDisplay { workingContext.imageSmoothingEnabled = false; // get the image - const response = await fetch(rewriteUrl(url)); + const modifiedUrl = OVERRIDES.RADAR_HOST ? url.replace(RADAR_HOST, OVERRIDES.RADAR_HOST) : url; + const response = await fetch(rewriteUrl(modifiedUrl)); // test response if (!response.ok) throw new Error(`Unable to fetch radar error ${response.status} ${response.statusText} from ${response.url}`); diff --git a/src/overrides.mjs b/src/overrides.mjs new file mode 100644 index 0000000..9b1f374 --- /dev/null +++ b/src/overrides.mjs @@ -0,0 +1,10 @@ +// read overrides from environment variables + +const OVERRIDES = {}; +Object.entries(process.env).forEach(([key, value]) => { + if (key.match(/^OVERRIDE_/)) { + OVERRIDES[key.replace('OVERRIDE_', '')] = value; + } +}); + +export default OVERRIDES; diff --git a/views/index.ejs b/views/index.ejs index 037eb50..396f36f 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -28,9 +28,12 @@ + <% } else { %> - + + +