pinafore/routes/_api/utils.js
2018-02-24 14:49:28 -08:00

22 lines
652 B
JavaScript

const isLocalhost = process.browser && process.env.NODE_ENV !== 'production' &&
(document.location.hostname === 'localhost' ||
document.location.hostname === '127.0.0.1')
function targetIsLocalhost (instanceName) {
return process.browser && process.env.NODE_ENV !== 'production' &&
(instanceName.startsWith('localhost:') || instanceName.startsWith('127.0.0.1:'))
}
export function basename (instanceName) {
if (isLocalhost && targetIsLocalhost(instanceName)) {
return `http://${instanceName}`
}
return `https://${instanceName}`
}
export function auth (accessToken) {
return {
'Authorization': `Bearer ${accessToken}`
}
}