Skip to content

Instantly share code, notes, and snippets.

@D7Torres
D7Torres / endpoint.js
Created December 20, 2019 15:45
Endpoint Refactor - Simplified getProtocol() v4
const getProtocol = (service, isServerSide, environment) => {
if (isServerSide) {
return 'http'
}
if (service === 'webclient' || environment !== 'local') {
return 'https'
}
return 'http'
@D7Torres
D7Torres / endpoint.js
Created December 20, 2019 15:39
Endpoint Refactor - Simplified getProtocol() v3
const getProtocol = (service, isServerSide, environment) => {
...
if (service === 'webclient' ||
(service !== 'webclient' && environment !== 'local')) {
return 'https'
}
...
}
@D7Torres
D7Torres / endpoint.js
Last active December 20, 2019 15:29
Endpoint Refactor - Simplified getProtocol() v2
const getProtocol = (service, isServerSide, environment) => {
if (isServerSide) {
return 'http'
}
if (service === 'webclient') {
return 'https'
}
if (service !== 'webclient' && environment !== 'local') {
@D7Torres
D7Torres / endpoint.js
Last active February 10, 2020 11:32
Endpoint Refactor - Simplified getProtocol()
const getProtocol = (service, isServerSide, environment) => {
if (service === 'webclient' && !isServerSide) {
return 'https'
}
if (service !== 'webclient' && !isServerSide && environment !== 'local') {
return 'https'
}
return 'http'
@D7Torres
D7Torres / truth table.csv
Created December 20, 2019 14:25
Endpoint Refactor - Truth table
Service is Webclient Server Side Env is Local Returns
TRUE TRUE TRUE http
TRUE TRUE FALSE http
TRUE FALSE TRUE https
TRUE FALSE FALSE https
FALSE TRUE TRUE http
FALSE FALSE TRUE http
FALSE TRUE FALSE http
FALSE FALSE FALSE https
@D7Torres
D7Torres / truth table simple.csv
Created December 6, 2019 17:26
Endpoint Refactor - Truth table simplified
Service is Webclient Server Side Env is Local Returns
TRUE TRUE - http
TRUE FALSE - https
FALSE - TRUE http
FALSE TRUE FALSE http
FALSE FALSE FALSE https
@D7Torres
D7Torres / endpoint.js
Created December 6, 2019 16:05
Endpoint Refactor - Extracting getProtocol
const getProtocol = (service, isServerSide, environment) => {
if (service === 'webclient') {
if (isServerSide) {
return 'http'
}
return 'https'
} else {
if (environment === 'local') {
return 'http'
@D7Torres
D7Torres / endpoint.js
Last active April 30, 2020 18:52
Endpoint Refactor - complete endpoint file
const getProtocol = (service, isServerSide, environment) => {
if (isServerSide) {
return 'http'
}
if (service === 'webclient' || environment !== 'local') {
return 'https'
}
return 'http'
@D7Torres
D7Torres / endpoint.js
Created December 6, 2019 15:07
Endpoint Refactor - endpoint function final result
...
function endpoint(service, version = '') {
const protocol = getProtocol(service, __SERVER__, __ENV__)
const subdomain = getSubdomain(service, __SERVER__, __ENV__)
const path = getPath(service, __SERVER__, __ENV__, version)
const port = getPort(service, __ENV__, __CLIENT__)
return `${protocol}://${subdomain}.${__DOMAIN__}${port}${path}`
}
@D7Torres
D7Torres / yarn test:jest:coverage output
Created December 6, 2019 14:59
Endpoint Refactor - Test coverage output
-------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-------------------|----------|----------|----------|----------|-------------------|
... | ... | ... | ... | ... | ...|
endpoint.js | 100 | 100 | 100 | 100 | |
... | ... | ... | ... | ... | ...|
-------------------|----------|----------|----------|----------|-------------------|
Test Suites: 1 passed, 1 total
Tests: 12 passed, 12 total