aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar vantezzen <properly@protonmail.com>2019-08-23 12:57:46 +0200
committerLibravatar vantezzen <properly@protonmail.com>2019-08-23 12:57:46 +0200
commited987f542626c0d7b7c5cb4ef18beeeace67885f (patch)
treebf7d0eeb25b95f7f8a5ebb1691d90df899a48d31 /src
parentAutofix npm audit (diff)
downloadferdium-app-ed987f542626c0d7b7c5cb4ef18beeeace67885f.tar.gz
ferdium-app-ed987f542626c0d7b7c5cb4ef18beeeace67885f.tar.zst
ferdium-app-ed987f542626c0d7b7c5cb4ef18beeeace67885f.zip
Use API URL from store for workspaces and announcements
Diffstat (limited to 'src')
-rw-r--r--src/features/announcements/api.js4
-rw-r--r--src/features/apiBase.js24
-rw-r--r--src/features/workspaces/api.js10
3 files changed, 31 insertions, 7 deletions
diff --git a/src/features/announcements/api.js b/src/features/announcements/api.js
index a581bd8de..0741c0f87 100644
--- a/src/features/announcements/api.js
+++ b/src/features/announcements/api.js
@@ -1,6 +1,6 @@
1import { remote } from 'electron'; 1import { remote } from 'electron';
2import Request from '../../stores/lib/Request'; 2import Request from '../../stores/lib/Request';
3import { API, API_VERSION } from '../../environment'; 3import apiBase from '../apiBase'
4 4
5const debug = require('debug')('Franz:feature:announcements:api'); 5const debug = require('debug')('Franz:feature:announcements:api');
6 6
@@ -21,7 +21,7 @@ export const announcementsApi = {
21 21
22 async getAnnouncement(version) { 22 async getAnnouncement(version) {
23 debug('fetching release announcement from api'); 23 debug('fetching release announcement from api');
24 const url = `${API}/${API_VERSION}/announcements/${version}`; 24 const url = `${apiBase()}/announcements/${version}`;
25 const response = await window.fetch(url, { method: 'GET' }); 25 const response = await window.fetch(url, { method: 'GET' });
26 if (!response.ok) return null; 26 if (!response.ok) return null;
27 return response.json(); 27 return response.json();
diff --git a/src/features/apiBase.js b/src/features/apiBase.js
new file mode 100644
index 000000000..961414668
--- /dev/null
+++ b/src/features/apiBase.js
@@ -0,0 +1,24 @@
1/**
2 * Get API base URL from store
3 */
4import {
5 API_VERSION
6} from '../environment';
7
8const apiBase = () => {
9 let url;
10 if (!window.ferdi.stores.settings) {
11 // Stores have not yet been loaded - send invalid URL to force a retry when stores are loaded
12 url = 'https://localhost:9999';
13 } else if (window.ferdi.stores.settings.all.app.server) {
14 // Load URL from store
15 url = window.ferdi.stores.settings.all.app.server;
16 } else {
17 // Use default server url
18 url = SERVER_URL;
19 }
20
21 return `${url}/${API_VERSION}`;
22}
23
24export default apiBase \ No newline at end of file
diff --git a/src/features/workspaces/api.js b/src/features/workspaces/api.js
index 0ec20c9ea..ff0e54a7a 100644
--- a/src/features/workspaces/api.js
+++ b/src/features/workspaces/api.js
@@ -1,14 +1,14 @@
1import { pick } from 'lodash'; 1import { pick } from 'lodash';
2import { sendAuthRequest } from '../../api/utils/auth'; 2import { sendAuthRequest } from '../../api/utils/auth';
3import { API, API_VERSION } from '../../environment';
4import Request from '../../stores/lib/Request'; 3import Request from '../../stores/lib/Request';
5import Workspace from './models/Workspace'; 4import Workspace from './models/Workspace';
5import apiBase from '../apiBase'
6 6
7const debug = require('debug')('Franz:feature:workspaces:api'); 7const debug = require('debug')('Franz:feature:workspaces:api');
8 8
9export const workspaceApi = { 9export const workspaceApi = {
10 getUserWorkspaces: async () => { 10 getUserWorkspaces: async () => {
11 const url = `${API}/${API_VERSION}/workspace`; 11 const url = `${apiBase()}/workspace`;
12 debug('getUserWorkspaces GET', url); 12 debug('getUserWorkspaces GET', url);
13 const result = await sendAuthRequest(url, { method: 'GET' }); 13 const result = await sendAuthRequest(url, { method: 'GET' });
14 debug('getUserWorkspaces RESULT', result); 14 debug('getUserWorkspaces RESULT', result);
@@ -18,7 +18,7 @@ export const workspaceApi = {
18 }, 18 },
19 19
20 createWorkspace: async (name) => { 20 createWorkspace: async (name) => {
21 const url = `${API}/${API_VERSION}/workspace`; 21 const url = `${apiBase()}/workspace`;
22 const options = { 22 const options = {
23 method: 'POST', 23 method: 'POST',
24 body: JSON.stringify({ name }), 24 body: JSON.stringify({ name }),
@@ -31,7 +31,7 @@ export const workspaceApi = {
31 }, 31 },
32 32
33 deleteWorkspace: async (workspace) => { 33 deleteWorkspace: async (workspace) => {
34 const url = `${API}/${API_VERSION}/workspace/${workspace.id}`; 34 const url = `${apiBase()}/workspace/${workspace.id}`;
35 debug('deleteWorkspace DELETE', url); 35 debug('deleteWorkspace DELETE', url);
36 const result = await sendAuthRequest(url, { method: 'DELETE' }); 36 const result = await sendAuthRequest(url, { method: 'DELETE' });
37 debug('deleteWorkspace RESULT', result); 37 debug('deleteWorkspace RESULT', result);
@@ -40,7 +40,7 @@ export const workspaceApi = {
40 }, 40 },
41 41
42 updateWorkspace: async (workspace) => { 42 updateWorkspace: async (workspace) => {
43 const url = `${API}/${API_VERSION}/workspace/${workspace.id}`; 43 const url = `${apiBase()}/workspace/${workspace.id}`;
44 const options = { 44 const options = {
45 method: 'PUT', 45 method: 'PUT',
46 body: JSON.stringify(pick(workspace, ['name', 'services'])), 46 body: JSON.stringify(pick(workspace, ['name', 'services'])),