Created
May 28, 2019 18:47
-
-
Save mattpocock/d8ba68fc038f7ab839ef26235ff0ede6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import JsonApi from 'devour-client' | |
| import apiConfig from 'javascript/config' | |
| import modelData from 'javascript/models' | |
| const api = new JsonApi(apiConfig) | |
| api.headers = Object.assign(apiConfig.headers, api.headers) | |
| api.insertMiddlewareBefore('axios-request', { | |
| name: 'set-auth-token', | |
| req: payload => { | |
| const token = localStorage.getItem('AUTH_TOKEN') | |
| if (token) { | |
| api.headers.Authorization = 'Bearer ' + token | |
| payload.req.headers.Authorization = 'Bearer ' + token | |
| } else { | |
| delete api.headers.Authorization | |
| delete payload.req.headers.Authorization | |
| } | |
| return payload | |
| } | |
| }) | |
| api.define('page', modelData.pages) | |
| api.define('collection', modelData.collections) | |
| api.define('page-image', modelData.pageImages) | |
| api.define('content-position', modelData.contentPositions) | |
| api.define('meta-datum', modelData.metaData) | |
| export default api |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Continue on with the definitions until the whole api is specced out.