Skip to content
Discussion options

You must be logged in to vote

Currently, Bruno doesn't have any native API to check this. But as a workaround, you could do

const resolveHost = async (primaryUrl, fallbackUrl) => {
  try {
    await bru.sendRequest({ url: primaryUrl, timeout: 2000 });
  } catch(e) {
    if (e.code === 'ECONNREFUSED') {
      return fallbackUrl;
    }
  }

  return primaryUrl;
}

const activeHost = await resolveHost('http://localhost:9653', 'https://echo.usebruno.com');

// bru.setVar('host', activeHost);
// bru.setEnvVar('host', activeHost); 
bru.setGlobalEnvVar('host', activeHost); 

Read more about variables here: https://docs.usebruno.com/variables/overview

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@pkfox
Comment options

Answer selected by pkfox
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants