mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-21 19:19:31 -07:00
update user-agent header, now allowed in some browsers
This commit is contained in:
@@ -5,6 +5,11 @@ const text = (url, params) => fetchAsync(url, 'text', params);
|
|||||||
const blob = (url, params) => fetchAsync(url, 'blob', params);
|
const blob = (url, params) => fetchAsync(url, 'blob', params);
|
||||||
|
|
||||||
const fetchAsync = async (_url, responseType, _params = {}) => {
|
const fetchAsync = async (_url, responseType, _params = {}) => {
|
||||||
|
// add user agent header to json request at api.weather.gov
|
||||||
|
const headers = {};
|
||||||
|
if (_url.match(/api\.weather\.gov/)) {
|
||||||
|
headers['user-agent'] = 'Weatherstar 4000+; weatherstar@netbymatt.com';
|
||||||
|
}
|
||||||
// combine default and provided parameters
|
// combine default and provided parameters
|
||||||
const params = {
|
const params = {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@@ -12,6 +17,7 @@ const fetchAsync = async (_url, responseType, _params = {}) => {
|
|||||||
type: 'GET',
|
type: 'GET',
|
||||||
retryCount: 0,
|
retryCount: 0,
|
||||||
..._params,
|
..._params,
|
||||||
|
headers,
|
||||||
};
|
};
|
||||||
// store original number of retries
|
// store original number of retries
|
||||||
params.originalRetries = params.retryCount;
|
params.originalRetries = params.retryCount;
|
||||||
|
|||||||
Reference in New Issue
Block a user