Skip to content

Commit

Permalink
Merge pull request #578 from bluehost/fix/staging-api-urls
Browse files Browse the repository at this point in the history
staging api fetch helper: append the path after the url returns from runtime
  • Loading branch information
circlecube authored Aug 2, 2023
2 parents aefab34 + 95f1df0 commit d03ce6f
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/app/pages/staging/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ const Staging = () => {
setIsError(false);
setIsLoading(true);
stagingApiFetch(
'staging/',
'staging',
null,
'GET',
(response) => {
// console.log('Init Staging Data:', response);
Expand All @@ -299,8 +300,9 @@ const Staging = () => {
makeNotice( 'creating', 'Working...', 'Creating a staging site, this should take about a minute.', 'info', 8000 );
// setIsCreatingStaging(true);
stagingApiFetch(
'staging/',
'POST',
'staging',
null,
'POST',
(response) => {
// console.log('Create Staging Callback', response);
if ( response.hasOwnProperty('status') ) {
Expand All @@ -324,7 +326,8 @@ const Staging = () => {
// console.log('delete staging');
makeNotice( 'deleting', 'Working...', 'Deleting the staging site, this should take about a minute.', 'info', 8000 );
stagingApiFetch(
'staging/',
'staging',
null,
'DELETE',
(response) => {
// console.log('Delete staging callback', response);
Expand All @@ -349,7 +352,8 @@ const Staging = () => {
// console.log('clone production to staging');
makeNotice( 'cloning', 'Working...', 'Cloning production to staging, this should take about a minute.', 'info', 8000 );
stagingApiFetch(
'staging/clone/',
'staging/clone',
null,
'POST',
(response) => {
// console.log('Clone Callback', response);
Expand Down Expand Up @@ -409,7 +413,8 @@ const Staging = () => {
makeNotice( 'switching', 'Working...', `Switching to the ${env} environment, this should take about a minute.`, 'info', 8000 );

stagingApiFetch(
`staging/switch-to&env=${env}`,
'staging/switch-to',
{'env': env},
'GET',
(response) => {
// console.log('Switch Callback', response);
Expand All @@ -435,7 +440,8 @@ const Staging = () => {
// console.log('Deploy', type);
makeNotice( 'deploying', 'Working...', 'Deploying from staging to production, this should take about a minute.', 'info', 8000 );
stagingApiFetch(
`staging/deploy&type=${type}`,
'staging/deploy',
{'type': type},
'POST',
(response) => {
// console.log('Deploy Callback', response);
Expand Down Expand Up @@ -464,16 +470,17 @@ const Staging = () => {
* @param passError setter for the error in component
* @return apiFetch promise
*/
const stagingApiFetch = (path = '', method = 'GET', thenCallback, errorCallback = catchError) => {
// setIsError( false );
// setIsLoading( true );
const stagingApiFetch = (
path = '',
qs = {},
method = 'GET',
thenCallback,
errorCallback = catchError
) => {
setIsThinking( true );
return apiFetch({
url: NewfoldRuntime.createApiUrl( apiNamespace + path ),
url: NewfoldRuntime.createApiUrl( apiNamespace + path, qs),
method,
// beforeSend: (xhr) => {
// xhr.setRequestHeader( 'X-WP-Nonce', restnonce );
// },
}).then( (response) => {
thenCallback( response );
}).catch( (error) => {
Expand Down

0 comments on commit d03ce6f

Please sign in to comment.