pinafore/routes/_api/utils.js
2018-02-24 21:27:32 -08:00

21 lines
526 B
JavaScript

const isLocalhost = !process.browser ||
location.hostname === 'localhost' ||
location.hostname === '127.0.0.1'
function targetIsLocalhost (instanceName) {
return 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}`
}
}