diff options
author | Claire <claire.github-309c@sitedethib.com> | 2022-10-11 10:32:31 +0200 |
---|---|---|
committer | Claire <claire.github-309c@sitedethib.com> | 2022-10-11 11:30:52 +0200 |
commit | c285546052f20f675569c9b2c82146ecbcb398ab (patch) | |
tree | c048a00e10ff9d6842f288d161b7eb7bab589fd1 /app/javascript/flavours/glitch/util | |
parent | 64342a87b4a5c803198190ba130b83642a5fd0c8 (diff) |
Move flavours/glitch/util/api to flavours/glitch/api
Diffstat (limited to 'app/javascript/flavours/glitch/util')
-rw-r--r-- | app/javascript/flavours/glitch/util/api.js | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/app/javascript/flavours/glitch/util/api.js b/app/javascript/flavours/glitch/util/api.js deleted file mode 100644 index 90d8465ef..000000000 --- a/app/javascript/flavours/glitch/util/api.js +++ /dev/null @@ -1,52 +0,0 @@ -import axios from 'axios'; -import ready from './ready'; -import LinkHeader from 'http-link-header'; - -export const getLinks = response => { - const value = response.headers.link; - - if (!value) { - return { refs: [] }; - } - - return LinkHeader.parse(value); -}; - -const csrfHeader = {}; - -const setCSRFHeader = () => { - const csrfToken = document.querySelector('meta[name=csrf-token]'); - - if (csrfToken) { - csrfHeader['X-CSRF-Token'] = csrfToken.content; - } -}; - -ready(setCSRFHeader); - -const authorizationHeaderFromState = getState => { - const accessToken = getState && getState().getIn(['meta', 'access_token'], ''); - - if (!accessToken) { - return {}; - } - - return { - 'Authorization': `Bearer ${accessToken}`, - }; -}; - -export default getState => axios.create({ - headers: { - ...csrfHeader, - ...authorizationHeaderFromState(getState), - }, - - transformResponse: [function (data) { - try { - return JSON.parse(data); - } catch(Exception) { - return data; - } - }], -}); |