diff options
author | vantezzen <properly@protonmail.com> | 2019-08-23 12:57:46 +0200 |
---|---|---|
committer | vantezzen <properly@protonmail.com> | 2019-08-23 12:57:46 +0200 |
commit | ed987f542626c0d7b7c5cb4ef18beeeace67885f (patch) | |
tree | bf7d0eeb25b95f7f8a5ebb1691d90df899a48d31 /src/features | |
parent | Autofix npm audit (diff) | |
download | ferdium-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/features')
-rw-r--r-- | src/features/announcements/api.js | 4 | ||||
-rw-r--r-- | src/features/apiBase.js | 24 | ||||
-rw-r--r-- | src/features/workspaces/api.js | 10 |
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 @@ | |||
1 | import { remote } from 'electron'; | 1 | import { remote } from 'electron'; |
2 | import Request from '../../stores/lib/Request'; | 2 | import Request from '../../stores/lib/Request'; |
3 | import { API, API_VERSION } from '../../environment'; | 3 | import apiBase from '../apiBase' |
4 | 4 | ||
5 | const debug = require('debug')('Franz:feature:announcements:api'); | 5 | const 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 | */ | ||
4 | import { | ||
5 | API_VERSION | ||
6 | } from '../environment'; | ||
7 | |||
8 | const 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 | |||
24 | export 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 @@ | |||
1 | import { pick } from 'lodash'; | 1 | import { pick } from 'lodash'; |
2 | import { sendAuthRequest } from '../../api/utils/auth'; | 2 | import { sendAuthRequest } from '../../api/utils/auth'; |
3 | import { API, API_VERSION } from '../../environment'; | ||
4 | import Request from '../../stores/lib/Request'; | 3 | import Request from '../../stores/lib/Request'; |
5 | import Workspace from './models/Workspace'; | 4 | import Workspace from './models/Workspace'; |
5 | import apiBase from '../apiBase' | ||
6 | 6 | ||
7 | const debug = require('debug')('Franz:feature:workspaces:api'); | 7 | const debug = require('debug')('Franz:feature:workspaces:api'); |
8 | 8 | ||
9 | export const workspaceApi = { | 9 | export 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'])), |