Repository URL to install this package:
|
Version:
3.1.0 ▾
|
/* eslint-disable max-statements */
const IS_LOCAL_PRODUCTION = process.env.LOCAL_PRODUCTION === 'true'
let logged = false
function logOnce(msg) {
if (logged === false) {
logged = true
console.log('\n\n\n')
console.log(msg)
console.log('\n\n\n')
}
}
// vvvvvvv shared with /dist
function getEnvVariable(name, fallback = undefined) {
return process.env[name] || process.env[name.toUpperCase()] || fallback
}
function getDefaultUrl() {
switch (true) {
// dynamic
case !!getEnvVariable('SERVER_URL'):
getEnvVariable('SERVER_URL')
// statically built
case !!process.env.SERVER_URL:
return process.env.SERVER_URL
default: {
console.warn('getDynamicPaths USING DEFAULT!!!')
// although we may want to ensure url is baked into bundle in the build
if (typeof window === 'object') {
return window.location.protocol + '//' + window.location.host
} else {
// throw new TypeError('NO VALID URL CONFIGURED')
}
}
}
}
function getApiUrl() {
// we want to use the direct value, so it gets code replaced
const ENV_API_VALUE = process.env.API_URL || getEnvVariable('API_URL', '')
return ENV_API_VALUE === '""' ? '' : ENV_API_VALUE
}
/**
* @todo - fix it here !!!!!! this is removing 3000 from localhos
* need to remove this and the other bad file and the one in webpack
*/
function getCoreEnvVariables() {
const API_URL = getApiUrl()
const HOST =
IS_LOCAL_PRODUCTION === true ? 'localhost' : getEnvVariable('HOST')
const PORT = getEnvVariable('PORT', 3000)
const CLIENT_DEV_PORT = process.env.CLIENT_DEV_PORT
const SERVER_URL = process.env.SERVER_URL
const paths = {
HOST,
PORT,
CLIENT_DEV_PORT,
SERVER_URL,
API_URL,
}
logOnce(paths)
return paths
}
function getAbsoluteUrl() {
const { SERVER_URL } = getCoreEnvVariables()
return getEnvVariable('SERVER_URL', SERVER_URL)
}
function getProxyUrl() {
const { API_URL } = getCoreEnvVariables()
return API_URL
}
export {
getDefaultUrl,
getAbsoluteUrl,
getEnvVariable,
getCoreEnvVariables,
getProxyUrl,
}
export default {
getDefaultUrl,
getAbsoluteUrl,
getEnvVariable,
getCoreEnvVariables,
getProxyUrl,
}