pinafore/routes/_api/utils.js

16 lines
552 B
JavaScript
Raw Normal View History

const isLocalhost = process.browser && process.env.NODE_ENV !== 'production' &&
(document.location.hostname === 'localhost' ||
document.location.hostname === '127.0.0.1')
2018-02-09 06:29:29 +00:00
function targetIsLocalhost (instanceName) {
return process.browser && process.env.NODE_ENV !== 'production' &&
(instanceName.startsWith('localhost:') || instanceName.startsWith('127.0.0.1:'))
}
2018-02-09 06:29:29 +00:00
export function basename (instanceName) {
if (isLocalhost && targetIsLocalhost(instanceName)) {
return `http://${instanceName}`
}
return `https://${instanceName}`
2018-02-09 06:29:29 +00:00
}