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

[GH-43] Use SiteUrl for calls from the webapp #58

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion webapp/src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function getAttributes(userID = '') {

let data = [];
try {
data = await Client.getAttributes(userID);
data = await Client.getAttributes(getState(), userID);
sudiptog81 marked this conversation as resolved.
Show resolved Hide resolved
} catch (error) {
if (error.status === 404) {
dispatch({
Expand Down
10 changes: 3 additions & 7 deletions webapp/src/client/client.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import {Client4} from 'mattermost-redux/client';
import {ClientError} from 'mattermost-redux/client/client4';

import {id as pluginId} from '../manifest';
import {getSiteURL} from '../selectors';

export default class Client {
constructor() {
this.url = `/plugins/${pluginId}/api/v1`;
}

getAttributes = async (userID = '') => {
return this.doGet(`${this.url}/attributes?user_id=` + userID);
getAttributes = async (state = {}, userID = '') => {
sudiptog81 marked this conversation as resolved.
Show resolved Hide resolved
return this.doGet(`${getSiteURL(state)}/attributes?user_id=${userID}`);
};

doGet = async (url, body, headers = {}) => {
Expand Down
18 changes: 18 additions & 0 deletions webapp/src/selectors/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {getConfig} from 'mattermost-redux/selectors/entities/general';

import {id as pluginId} from '../manifest';

export const getSiteURL = (state) => {
const config = getConfig(state);

let basePath = '';
if (config && config.SiteURL) {
basePath = new URL(config.SiteURL).pathname;

if (basePath && basePath[basePath.length - 1] === '/') {
basePath = basePath.substr(0, basePath.length - 1);
}
}

return `${basePath}/plugins/${pluginId}/api/v1`;
};