-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-191: Allow loading CMS data via CMS script
So that Portal and Docs need not reinvent the wheel.
- Loading branch information
1 parent
793e10a
commit 67149c2
Showing
3 changed files
with
36 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Return data from an endpoint | ||
* @param {string} dataURL - The URL from which to get the data | ||
* @param {('html'|'json'|'text')} dataType - The type of data to retrieve | ||
* @returns {Promise<string>} Promise that returns markup if resolved | ||
*/ | ||
export function getFromURL(dataURL, dataType) { | ||
const isValidURL = (dataURL && typeof dataURL === 'string'); | ||
|
||
if (isValidURL) { | ||
return fetch(dataURL).then(response => { | ||
let data; | ||
|
||
switch (dataType) { | ||
case 'json': | ||
data = response.json(); | ||
break; | ||
case 'html': | ||
case 'text': | ||
default: | ||
data = response.text(); | ||
break; | ||
} | ||
|
||
return data; | ||
}).catch(err => { | ||
console.error(err); | ||
}); | ||
} else { | ||
return Promise.reject(new Error('Invalid URL provided')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../Core-CMS/taccsite_cms/static |