Skip to content

Instantly share code, notes, and snippets.

@mattpocock
Created May 28, 2019 18:47
Show Gist options
  • Select an option

  • Save mattpocock/d8ba68fc038f7ab839ef26235ff0ede6 to your computer and use it in GitHub Desktop.

Select an option

Save mattpocock/d8ba68fc038f7ab839ef26235ff0ede6 to your computer and use it in GitHub Desktop.
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
@mattpocock

Copy link
Copy Markdown
Author

Continue on with the definitions until the whole api is specced out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment