-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add other methods #1
base: vanilla-js
Are you sure you want to change the base?
Conversation
argus.js
Outdated
@@ -12,8 +12,13 @@ const ArgusJS = function(token) { | |||
}, false); | |||
|
|||
return { | |||
token: () => currentToken, | |||
get: (url) => fetch(url, { "method": "GET", "headers": { "Authorization": "Token " + currentToken } }) | |||
get: (url) => fetch(`${mdr_url}${url}`, { "method": "GET", "headers": { "Authorization": "Bearer " + currentToken.access } }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a function to join the base URL and the path? It should handle the URL having a leading '/' or not.
e.g.,
const mdrURL = '...';
const buildURL = (path) => (new URL(path, mdrURL)).href;
@@ -2,7 +2,7 @@ const MESSAGE_ARGUS_TOKEN_REFRESH = "argus-token-refresh"; | |||
const MESSAGE_ARGUS_TOKEN_REQUEST = "argus-token-request"; | |||
const MESSAGE_ARGUS_TOKEN_RESPONSE = "argus-token-response"; | |||
|
|||
const ArgusJS = function(token) { | |||
const ArgusJS = function(token, mdrUrl) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You also need to update line 30 to include the URL:
resolve(ArgusJS(event.data.token));
-> resolve(ArgusJS(event.data.token, event.data.mdr_url));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initArgusJS
needs to be changed to an exported function so that it can be imported, e.g.,
export function initArgusJS() {
argus.js
Outdated
token: () => currentToken, | ||
get: (url) => fetch(url, { "method": "GET", "headers": { "Authorization": "Token " + currentToken } }) | ||
get: (url) => fetch(`${mdrUrl}${url}`, { "method": "GET", "headers": { "Authorization": "Bearer " + currentToken.access } }), | ||
post: (url, data) => fetch(`${mdrUrl}${url}`, { "method": "POST", "headers": { "Authorization": "Bearer " + currentToken.access }, body: JSON.stringify(data) }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For all the http request types that have a body you need to explicitly define the content type in the headers as the following 'Content-Type': 'application/json; charset=UTF-8'
No description provided.