Skip to content

Instantly share code, notes, and snippets.

@arkumish
Created February 26, 2021 03:24
Show Gist options
  • Save arkumish/9efe092d648350a6e602f64ed4d0981a to your computer and use it in GitHub Desktop.
Save arkumish/9efe092d648350a6e602f64ed4d0981a to your computer and use it in GitHub Desktop.
Api_root for multiple environment backend apis.
let backendHost;
const hostname = window && window.location && window.location.hostname;
if(hostname === 'localhost') {
backendHost = 'http://localhost:5000'; //when frontend and backend are on the same server
} else if(hostname === 'yourWebsitename') { //eg markde.netlify.com
backendHost = 'backend_server_address'; //for backend hosted on different server not same as frontend
} else{
backendHost = '';
}
export const API_ROOT = `${backendHost}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment