Allow api action to make arbitrary HTTP(S) requests.

If the URL is an absolute HTTP(S) one, we use it as-is.
This commit is contained in:
D. Berge
2021-05-24 13:35:36 +02:00
parent d02edb4e76
commit 56d1279584

View File

@@ -13,7 +13,8 @@ async function api ({state, commit, dispatch}, [resource, init = {}, cb]) {
init.body = JSON.stringify(init.body);
}
}
const res = await fetch(`${state.apiUrl}${resource}`, init);
const url = /^https?:\/\//i.test(resource) ? resource : (state.apiUrl + resource);
const res = await fetch(url, init);
if (typeof cb === 'function') {
cb(null, res);
}