Skip to content
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

Open
wants to merge 4 commits into
base: vanilla-js
Choose a base branch
from
Open

Add other methods #1

wants to merge 4 commits into from

Conversation

SophiaNSL
Copy link

No description provided.

argus.js Outdated Show resolved Hide resolved
argus.js Outdated Show resolved Hide resolved
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 } }),
Copy link

@paulsamways paulsamways Jul 26, 2024

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;

argus.js Outdated Show resolved Hide resolved
@@ -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) {

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));

Copy link

@paulsamways paulsamways left a 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) }),

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants