Skip to content

Instantly share code, notes, and snippets.

@D7Torres
Created December 6, 2019 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save D7Torres/e0465618cb24f4a138fd20bf37ff4cda to your computer and use it in GitHub Desktop.
Save D7Torres/e0465618cb24f4a138fd20bf37ff4cda to your computer and use it in GitHub Desktop.
Endpoint Refactor - Extracting getProtocol
const getProtocol = (service, isServerSide, environment) => {
if (service === 'webclient') {
if (isServerSide) {
return 'http'
}
return 'https'
} else {
if (environment === 'local') {
return 'http'
} else {
if (isServerSide) {
return 'http'
} else {
return 'https'
}
}
}
}
function endpoint(service, version = '') {
const protocol = getProtocol(service, __SERVER__, __ENV__)
// Rest of the mess here
...
const url = `${protocol}://${domain}`
return url
}
export default endpoint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment