Skip to content

Commit

Permalink
attach new build in /dist
Browse files Browse the repository at this point in the history
  • Loading branch information
mwood77 committed Feb 23, 2025
1 parent 83be0b5 commit 05e86db
Show file tree
Hide file tree
Showing 479 changed files with 86,286 additions and 0 deletions.
43 changes: 43 additions & 0 deletions dist/cors/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// pass through api requests

// http(s) modules
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+, [email protected])';
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);
});
};
44 changes: 44 additions & 0 deletions dist/cors/outlook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// pass through api requests

// http(s) modules
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+, [email protected])';
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);
});
};
44 changes: 44 additions & 0 deletions dist/cors/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// pass through api requests

// http(s) modules
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+, [email protected])';
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);
});
};
22 changes: 22 additions & 0 deletions dist/datagenerators/chunk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// turn a long array into a set of smaller chunks

const chunk = (data, chunkSize = 10) => {
const chunks = [];

let thisChunk = [];

data.forEach((d) => {
if (thisChunk.length >= chunkSize) {
chunks.push(thisChunk);
thisChunk = [];
}
thisChunk.push(d);
});

// final chunk
if (thisChunk.length > 0) chunks.push(thisChunk);

return chunks;
};

module.exports = chunk;
24 changes: 24 additions & 0 deletions dist/datagenerators/https.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// async https wrapper

const https = require('https');

module.exports = (url) => new Promise((resolve, reject) => {
const headers = {};
headers['user-agent'] = '(WeatherStar 4000+ data generator, [email protected])';

https.get(url, {
headers,
}, (res) => {
if (res.statusCode === 200) {
const buffers = [];
res.on('data', (data) => buffers.push(data));
res.on('end', () => resolve(Buffer.concat(buffers).toString()));
} else {
console.log(res);
reject(new Error(`Unable to get: ${url}`));
}
}).on('error', (e) => {
console.log(e);
reject(e);
});
});
Loading

0 comments on commit 05e86db

Please sign in to comment.