mattermost / mattermost-plugin-nps

Collect and Send NPS surveys
Apache License 2.0
8 stars 10 forks source link

Use SiteURL for all calls from the webapp #70

Open mickmister opened 4 years ago

mickmister commented 4 years ago

If the server's SiteURL is configured with a subpath, the webapp's API calls do not work. The task here is to make this plugin's client to prefix its URLs with the SiteURL.

Here's an example of how the SiteURL may be computed: https://github.com/mattermost/mattermost-plugin-jira/blob/19a9c2442817132b4eee5c77e259b80a40188a6a/webapp/src/selectors/index.js#L13-L26

mickmister commented 4 years ago

By default, requests from the frontend to the server are not prefixed with any host. For example, a fetch request like fetch('/api4/users') will be sent to /api4/users. One problem this has is if the server is being hosted on a subpath, or for some reason the server's SiteURL happens to be a different host than the domain that the frontend is connected to, we need to prefix the API calls with the SiteURL.

An example before the fix:

fetch('/api4/users');

But we want

const siteURL = getSiteURL(state);
fetch(siteURL + '/api4/users');

The link in this issue's description is to a different project, just to show how to get the SiteURL. This fix needs to be applied to other plugin projects as well, such as the nps plugin here. The SiteURL is currently not being used in the frontend portion of the nps plugin.