diff --git a/cors/index.mjs b/cors/index.mjs deleted file mode 100644 index 2dd1d8e..0000000 --- a/cors/index.mjs +++ /dev/null @@ -1,45 +0,0 @@ -// pass through api requests - -// http(s) modules -import https from 'https'; - -// url parsing -import queryString from 'querystring'; - -// return an express router -const cors = (req, res) => { - // add out-going headers - const headers = {}; - headers['user-agent'] = '(WeatherStar 4000+, ws4000@netbymatt.com)'; - headers.accept = req.headers.accept; - - // get query paramaters if the exist - const queryParams = Object.keys(req.query).reduce((acc, key) => { - // skip the paramater 'u' - if (key === 'u') return acc; - // 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}`; - - // get the page - https.get(`https://api.weather.gov${req.path}${query}`, { - headers, - }, (getRes) => { - // pull some info - const { statusCode } = getRes; - // pass the status code through - res.status(statusCode); - - // set headers - res.header('content-type', getRes.headers['content-type']); - // pipe to response - getRes.pipe(res); - }).on('error', (e) => { - console.error(e); - }); -}; - -export default cors; diff --git a/cors/outlook.mjs b/cors/outlook.mjs deleted file mode 100644 index 655c641..0000000 --- a/cors/outlook.mjs +++ /dev/null @@ -1,46 +0,0 @@ -// pass through api requests - -// http(s) modules -import https from 'https'; - -// url parsing -import queryString from 'querystring'; - -// return an express router -const outlook = (req, res) => { - // add out-going headers - const headers = {}; - headers['user-agent'] = '(WeatherStar 4000+, ws4000@netbymatt.com)'; - headers.accept = req.headers.accept; - - // get query paramaters if the exist - const queryParams = Object.keys(req.query).reduce((acc, key) => { - // skip the paramater 'u' - if (key === 'u') return acc; - // 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}`; - - // get the page - https.get(`https://www.cpc.ncep.noaa.gov/${req.path}${query}`, { - headers, - }, (getRes) => { - // pull some info - const { statusCode } = getRes; - // pass the status code through - res.status(statusCode); - - // set headers - res.header('content-type', getRes.headers['content-type']); - res.header('last-modified', getRes.headers['last-modified']); - // pipe to response - getRes.pipe(res); - }).on('error', (e) => { - console.error(e); - }); -}; - -export default outlook; diff --git a/cors/radar.mjs b/cors/radar.mjs deleted file mode 100644 index 1e5b6b2..0000000 --- a/cors/radar.mjs +++ /dev/null @@ -1,46 +0,0 @@ -// pass through api requests - -// http(s) modules -import https from 'https'; - -// url parsing -import queryString from 'querystring'; - -// return an express router -const radar = (req, res) => { - // add out-going headers - const headers = {}; - headers['user-agent'] = '(WeatherStar 4000+, ws4000@netbymatt.com)'; - headers.accept = req.headers.accept; - - // get query paramaters if the exist - const queryParams = Object.keys(req.query).reduce((acc, key) => { - // skip the paramater 'u' - if (key === 'u') return acc; - // 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}`; - - // get the page - https.get(`https://radar.weather.gov${req.path}${query}`, { - headers, - }, (getRes) => { - // pull some info - const { statusCode } = getRes; - // pass the status code through - res.status(statusCode); - - // set headers - res.header('content-type', getRes.headers['content-type']); - res.header('last-modified', getRes.headers['last-modified']); - // pipe to response - getRes.pipe(res); - }).on('error', (e) => { - console.error(e); - }); -}; - -export default radar; diff --git a/gulp/publish-frontend.mjs b/gulp/publish-frontend.mjs index 0dbc0eb..e37486d 100644 --- a/gulp/publish-frontend.mjs +++ b/gulp/publish-frontend.mjs @@ -137,6 +137,8 @@ const s3 = s3Upload({ const uploadSources = [ 'dist/**', '!dist/**/*.map', + '!dist/images/**/*', + '!dist/fonts/**/*', ]; const upload = () => src(uploadSources, { base: './dist', encoding: false }) .pipe(s3({ @@ -167,6 +169,9 @@ const uploadImages = () => src(imageSources, { base: './server', encoding: false }), ); +const copyImageSources = () => src(imageSources, { base: './server', encoding: false }) + .pipe(dest('./dist')); + const invalidate = () => cloudfront.send(new CreateInvalidationCommand({ DistributionId: process.env.DISTRIBUTION_ID, InvalidationBatch: { @@ -184,7 +189,7 @@ const buildPlaylist = async () => { return file('playlist.json', JSON.stringify(playlist)).pipe(dest('./dist')); }; -const buildDist = series(clean, parallel(buildJs, compressJsData, compressJsVendor, copyCss, compressHtml, copyOtherFiles, buildPlaylist)); +const buildDist = series(clean, parallel(buildJs, compressJsData, compressJsVendor, copyCss, compressHtml, copyOtherFiles, buildPlaylist, copyImageSources)); // upload_images could be in parallel with upload, but _images logs a lot and has little changes // by running upload last the majority of the changes will be at the bottom of the log for easy viewing diff --git a/index.mjs b/index.mjs index 8c2169b..a09b706 100644 --- a/index.mjs +++ b/index.mjs @@ -1,9 +1,6 @@ import 'dotenv/config'; import express from 'express'; import fs from 'fs'; -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'; @@ -13,12 +10,6 @@ const port = process.env.WS4KP_PORT ?? 8080; // template engine app.set('view engine', 'ejs'); -// cors pass-thru to api.weather.gov -app.get('/stations/*station', corsPassThru); -app.get('/Conus/*radar', radarPassThru); -app.get('/products/*product', outlookPassThru); -app.get('/playlist.json', playlist); - // version const { version } = JSON.parse(fs.readFileSync('package.json')); @@ -80,11 +71,6 @@ const geoip = (req, res) => { // debugging if (process.env?.DIST === '1') { - // distribution - app.use('/images', express.static('./server/images')); - app.use('/fonts', express.static('./server/fonts')); - app.use('/scripts', express.static('./server/scripts')); - app.use('/geoip', geoip); app.use('/', express.static('./dist')); } else { // debugging @@ -92,6 +78,8 @@ if (process.env?.DIST === '1') { app.use('/geoip', geoip); app.get('/', index); app.get('*name', express.static('./server')); + // cors pass-thru to api.weather.gov + app.get('/playlist.json', playlist); } const server = app.listen(port, () => { diff --git a/server/scripts/modules/currentweather.mjs b/server/scripts/modules/currentweather.mjs index 543c9c9..c9ed112 100644 --- a/server/scripts/modules/currentweather.mjs +++ b/server/scripts/modules/currentweather.mjs @@ -42,7 +42,6 @@ class CurrentWeather extends WeatherDisplay { // station observations // eslint-disable-next-line no-await-in-loop observations = await json(`${station.id}/observations`, { - cors: true, data: { limit: 2, }, diff --git a/server/scripts/modules/radar.mjs b/server/scripts/modules/radar.mjs index baaef37..7b6681b 100644 --- a/server/scripts/modules/radar.mjs +++ b/server/scripts/modules/radar.mjs @@ -87,7 +87,7 @@ class Radar extends WeatherDisplay { const lists = (await Promise.all(baseUrls.map(async (url) => { try { // get a list of available radars - return text(url, { cors: true }); + return text(url); } catch (error) { console.log('Unable to get list of radars'); console.error(error);