mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-22 11:39:30 -07:00
radar host overrides
This commit is contained in:
@@ -12,7 +12,8 @@
|
|||||||
"RegionalCities": "readonly",
|
"RegionalCities": "readonly",
|
||||||
"StationInfo": "readonly",
|
"StationInfo": "readonly",
|
||||||
"SunCalc": "readonly",
|
"SunCalc": "readonly",
|
||||||
"NoSleep": "readonly"
|
"NoSleep": "readonly",
|
||||||
|
"OVERRIDES": "readonly"
|
||||||
},
|
},
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"ecmaVersion": "latest",
|
"ecmaVersion": "latest",
|
||||||
|
|||||||
@@ -14,9 +14,10 @@ import webpack from 'webpack-stream';
|
|||||||
import TerserPlugin from 'terser-webpack-plugin';
|
import TerserPlugin from 'terser-webpack-plugin';
|
||||||
import { readFile } from 'fs/promises';
|
import { readFile } from 'fs/promises';
|
||||||
import file from 'gulp-file';
|
import file from 'gulp-file';
|
||||||
|
import { CloudFrontClient, CreateInvalidationCommand } from '@aws-sdk/client-cloudfront';
|
||||||
|
import OVERRIDES from '../src/overrides.mjs';
|
||||||
|
|
||||||
// get cloudfront
|
// get cloudfront
|
||||||
import { CloudFrontClient, CreateInvalidationCommand } from '@aws-sdk/client-cloudfront';
|
|
||||||
import reader from '../src/playlist-reader.mjs';
|
import reader from '../src/playlist-reader.mjs';
|
||||||
|
|
||||||
const clean = () => deleteAsync(['./dist/**/*', '!./dist/readme.txt']);
|
const clean = () => deleteAsync(['./dist/**/*', '!./dist/readme.txt']);
|
||||||
@@ -113,6 +114,7 @@ const compressHtml = async () => {
|
|||||||
.pipe(ejs({
|
.pipe(ejs({
|
||||||
production: version,
|
production: version,
|
||||||
version,
|
version,
|
||||||
|
OVERRIDES,
|
||||||
}))
|
}))
|
||||||
.pipe(rename({ extname: '.html' }))
|
.pipe(rename({ extname: '.html' }))
|
||||||
.pipe(htmlmin({ collapseWhitespace: true }))
|
.pipe(htmlmin({ collapseWhitespace: true }))
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import corsPassThru from './cors/index.mjs';
|
|||||||
import radarPassThru from './cors/radar.mjs';
|
import radarPassThru from './cors/radar.mjs';
|
||||||
import outlookPassThru from './cors/outlook.mjs';
|
import outlookPassThru from './cors/outlook.mjs';
|
||||||
import playlist from './src/playlist.mjs';
|
import playlist from './src/playlist.mjs';
|
||||||
|
import OVERRIDES from './src/overrides.mjs';
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = process.env.WS4KP_PORT ?? 8080;
|
const port = process.env.WS4KP_PORT ?? 8080;
|
||||||
@@ -57,6 +58,7 @@ const index = (req, res) => {
|
|||||||
res.render('index', {
|
res.render('index', {
|
||||||
production: false,
|
production: false,
|
||||||
version,
|
version,
|
||||||
|
OVERRIDES,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import WeatherDisplay from './weatherdisplay.mjs';
|
|||||||
import { registerDisplay, timeZone } from './navigation.mjs';
|
import { registerDisplay, timeZone } from './navigation.mjs';
|
||||||
import * as utils from './radar-utils.mjs';
|
import * as utils from './radar-utils.mjs';
|
||||||
|
|
||||||
|
const RADAR_HOST = 'mesonet.agron.iastate.edu';
|
||||||
class Radar extends WeatherDisplay {
|
class Radar extends WeatherDisplay {
|
||||||
constructor(navId, elemId) {
|
constructor(navId, elemId) {
|
||||||
super(navId, elemId, 'Local Radar', true);
|
super(navId, elemId, 'Local Radar', true);
|
||||||
@@ -55,7 +56,7 @@ class Radar extends WeatherDisplay {
|
|||||||
const src = 'images/maps/radar.webp';
|
const src = 'images/maps/radar.webp';
|
||||||
this.baseMap = await loadImg(src);
|
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 baseUrlEnd = '/GIS/uscomp/?F=0&P=n0r*.png';
|
||||||
const baseUrls = [];
|
const baseUrls = [];
|
||||||
let date = DateTime.utc().minus({ days: 1 }).startOf('day');
|
let date = DateTime.utc().minus({ days: 1 }).startOf('day');
|
||||||
@@ -134,7 +135,8 @@ class Radar extends WeatherDisplay {
|
|||||||
workingContext.imageSmoothingEnabled = false;
|
workingContext.imageSmoothingEnabled = false;
|
||||||
|
|
||||||
// get the image
|
// 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
|
// test response
|
||||||
if (!response.ok) throw new Error(`Unable to fetch radar error ${response.status} ${response.statusText} from ${response.url}`);
|
if (!response.ok) throw new Error(`Unable to fetch radar error ${response.status} ${response.statusText} from ${response.url}`);
|
||||||
|
|||||||
10
src/overrides.mjs
Normal file
10
src/overrides.mjs
Normal file
@@ -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;
|
||||||
@@ -28,9 +28,12 @@
|
|||||||
<script type="text/javascript" src="resources/data.min.js?_=<%=production%>"></script>
|
<script type="text/javascript" src="resources/data.min.js?_=<%=production%>"></script>
|
||||||
<script type="text/javascript" src="resources/vendor.min.js?_=<%=production%>"></script>
|
<script type="text/javascript" src="resources/vendor.min.js?_=<%=production%>"></script>
|
||||||
<script type="text/javascript" src="resources/ws.min.js?_=<%=production%>"></script>
|
<script type="text/javascript" src="resources/ws.min.js?_=<%=production%>"></script>
|
||||||
|
<script type="text/javascript">const OVERRIDES=<%-JSON.stringify(OVERRIDES)%>;</script>
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
<link rel="stylesheet" type="text/css" href="styles/main.css" />
|
<link rel="stylesheet" type="text/css" href="styles/main.css" />
|
||||||
<script type="text/javascript" src="scripts/vendor/auto/nosleep.js"></script>
|
<!--<script type="text/javascript">const OVERRIDES={};</script>-->
|
||||||
|
<script type="text/javascript">OVERRIDES=<%-JSON.stringify(OVERRIDES)%>;</script>
|
||||||
|
<script type="text/javascript" src="scripts/vendor/auto/nosleep.js"></script>
|
||||||
<script type="text/javascript" src="scripts/vendor/auto/swiped-events.js"></script>
|
<script type="text/javascript" src="scripts/vendor/auto/swiped-events.js"></script>
|
||||||
<script type="text/javascript" src="scripts/vendor/auto/suncalc.js"></script>
|
<script type="text/javascript" src="scripts/vendor/auto/suncalc.js"></script>
|
||||||
<script type="module" src="scripts/modules/hazards.mjs"></script>
|
<script type="module" src="scripts/modules/hazards.mjs"></script>
|
||||||
|
|||||||
Reference in New Issue
Block a user