diff --git a/frontend/src/components/LogsViewer.vue b/frontend/src/components/LogsViewer.vue index 801efebb2..581e664fc 100644 --- a/frontend/src/components/LogsViewer.vue +++ b/frontend/src/components/LogsViewer.vue @@ -31,7 +31,7 @@ import { Button, TopBar, MainLayout } from 'pankow'; import LogsModel from '../models/LogsModel.js'; import AppModel from '../models/AppModel.js'; -const API_ORIGIN = import.meta.env.VITE_API_ORIGIN ? 'https://' + import.meta.env.VITE_API_ORIGIN : window.location.origin ; +const API_ORIGIN = import.meta.env.VITE_API_ORIGIN ? 'https://' + import.meta.env.VITE_API_ORIGIN : window.location.origin; export default { name: 'LogsViewer', @@ -43,7 +43,6 @@ export default { data() { return { accessToken: localStorage.token, - apiOrigin: API_ORIGIN || '', logsModel: null, appModel: null, busyRestart: false, @@ -113,10 +112,10 @@ export default { return; } - this.logsModel = LogsModel.create(this.apiOrigin, this.accessToken, this.type, this.id); + this.logsModel = LogsModel.create(API_ORIGIN, this.accessToken, this.type, this.id); if (this.type === 'app') { - this.appModel = AppModel.create(this.apiOrigin, this.accessToken, this.id); + this.appModel = AppModel.create(API_ORIGIN, this.accessToken, this.id); try { const app = await this.appModel.get(); diff --git a/frontend/src/components/Terminal.vue b/frontend/src/components/Terminal.vue index 058f5f0b3..0db46f090 100644 --- a/frontend/src/components/Terminal.vue +++ b/frontend/src/components/Terminal.vue @@ -73,7 +73,6 @@ export default { data() { return { accessToken: localStorage.token, - apiOrigin: API_ORIGIN || '', appModel: null, directoryModel: null, fatalError: false, @@ -115,7 +114,7 @@ export default { if (!downloadFileName) return; try { - await fetcher.head(`${this.apiOrigin}/api/v1/apps/${this.id}/download`, { + await fetcher.head(`${API_ORIGIN}/api/v1/apps/${this.id}/download`, { file: downloadFileName, access_token: this.accessToken }); @@ -126,7 +125,7 @@ export default { return; } - this.downloadFileDownloadUrl = `${this.apiOrigin}/api/v1/apps/${this.id}/download?file=${encodeURIComponent(downloadFileName)}&access_token=${this.accessToken}`; + this.downloadFileDownloadUrl = `${API_ORIGIN}/api/v1/apps/${this.id}/download?file=${encodeURIComponent(downloadFileName)}&access_token=${this.accessToken}`; // we have to click the link to make the browser do the download // don't know how to prevent the browsers @@ -197,7 +196,7 @@ export default { let execId; try { - const result = await fetcher.post(`${this.apiOrigin}/api/v1/apps/${this.id}/exec`, { cmd: [ '/bin/bash' ], tty: true, lang: 'C.UTF-8' }, { access_token: this.accessToken }); + const result = await fetcher.post(`${API_ORIGIN}/api/v1/apps/${this.id}/exec`, { cmd: [ '/bin/bash' ], tty: true, lang: 'C.UTF-8' }, { access_token: this.accessToken }); execId = result.body.id; } catch (error) { console.error('Cannot create socket.', error); @@ -220,7 +219,7 @@ export default { }); // websocket cannot use relative urls - const url = `${this.apiOrigin.replace('https', 'wss')}/api/v1/apps/${this.id}/exec/${execId}/startws?tty=true&rows=${this.terminal.rows}&columns=${this.terminal.cols}&access_token=${this.accessToken}`; + const url = `${API_ORIGIN.replace('https', 'wss')}/api/v1/apps/${this.id}/exec/${execId}/startws?tty=true&rows=${this.terminal.rows}&columns=${this.terminal.cols}&access_token=${this.accessToken}`; this.socket = new WebSocket(url); this.terminal.loadAddon(new AttachAddon(this.socket)); @@ -261,8 +260,8 @@ export default { this.id = id; this.name = id; - this.appModel = create(this.apiOrigin, this.accessToken, this.id); - this.directoryModel = createDirectoryModel(this.apiOrigin, this.accessToken, `apps/${id}`); + this.appModel = create(API_ORIGIN, this.accessToken, this.id); + this.directoryModel = createDirectoryModel(API_ORIGIN, this.accessToken, `apps/${id}`); try { const app = await this.appModel.get(); diff --git a/frontend/src/i18n.js b/frontend/src/i18n.js index f97b5d457..9c97a4969 100644 --- a/frontend/src/i18n.js +++ b/frontend/src/i18n.js @@ -1,4 +1,4 @@ -const API_ORIGIN = import.meta.env.VITE_API_ORIGIN ? 'https://' + import.meta.env.VITE_API_ORIGIN : ''; +const API_ORIGIN = import.meta.env.VITE_API_ORIGIN ? 'https://' + import.meta.env.VITE_API_ORIGIN : window.origin; import { createI18n } from 'vue-i18n'; import { fetcher } from 'pankow'; diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue index 7968a48dc..022db3309 100644 --- a/frontend/src/views/Home.vue +++ b/frontend/src/views/Home.vue @@ -111,7 +111,7 @@ import { ISTATES } from '../constants.js'; import PreviewPanel from '../components/PreviewPanel.vue'; import { createDirectoryModel } from '../models/DirectoryModel.js'; -const API_ORIGIN = import.meta.env.VITE_API_ORIGIN ? 'https://' + import.meta.env.VITE_API_ORIGIN : ''; +const API_ORIGIN = import.meta.env.VITE_API_ORIGIN ? 'https://' + import.meta.env.VITE_API_ORIGIN : window.origin; const BASE_URL = import.meta.env.BASE_URL || '/'; const beforeUnloadListener = (event) => { @@ -154,7 +154,6 @@ export default { files: [] }, accessToken: localStorage.token, - apiOrigin: API_ORIGIN || '', title: 'Cloudron', appLink: '', resourceType: '', @@ -221,7 +220,7 @@ export default { if (type === 'app') { let error, result; try { - result = await fetcher.get(`${this.apiOrigin}/api/v1/apps/${resourceId}`, { access_token: this.accessToken }); + result = await fetcher.get(`${API_ORIGIN}/api/v1/apps/${resourceId}`, { access_token: this.accessToken }); } catch (e) { error = e; } @@ -236,7 +235,7 @@ export default { } else if (type === 'volume') { let error, result; try { - result = await fetcher.get(`${this.apiOrigin}/api/v1/volumes/${resourceId}`, { access_token: this.accessToken }); + result = await fetcher.get(`${API_ORIGIN}/api/v1/volumes/${resourceId}`, { access_token: this.accessToken }); } catch (e) { error = e; } @@ -252,7 +251,7 @@ export default { } try { - const result = await fetcher.get(`${this.apiOrigin}/api/v1/dashboard/config`, { access_token: this.accessToken }); + const result = await fetcher.get(`${API_ORIGIN}/api/v1/dashboard/config`, { access_token: this.accessToken }); this.footerContent = marked.parse(result.body.footer); } catch (e) { console.error('Failed to fetch Cloudron config.', e); @@ -264,7 +263,7 @@ export default { this.resourceType = type; this.resourceId = resourceId; - this.directoryModel = createDirectoryModel(this.apiOrigin, this.accessToken, type === 'volume' ? `volumes/${resourceId}` : `apps/${resourceId}`); + this.directoryModel = createDirectoryModel(API_ORIGIN, this.accessToken, type === 'volume' ? `volumes/${resourceId}` : `apps/${resourceId}`); this.ownersModel = this.directoryModel.ownersModel; this.loadCwd(); @@ -276,7 +275,7 @@ export default { this.resourceType = toParams.type; this.resourceId = toParams.resourceId; - this.directoryModel = createDirectoryModel(this.apiOrigin, this.accessToken, toParams.type === 'volume' ? `volumes/${toParams.resourceId}` : `apps/${toParams.resourceId}`); + this.directoryModel = createDirectoryModel(API_ORIGIN, this.accessToken, toParams.type === 'volume' ? `volumes/${toParams.resourceId}` : `apps/${toParams.resourceId}`); } this.cwd = toParams.cwd ? `/${toParams.cwd.join('/')}` : '/'; @@ -564,7 +563,7 @@ export default { let error, result; try { - result = await fetcher.post(`${this.apiOrigin}/api/v1/apps/${this.resourceId}/restart`, null, { access_token: this.accessToken }); + result = await fetcher.post(`${API_ORIGIN}/api/v1/apps/${this.resourceId}/restart`, null, { access_token: this.accessToken }); } catch (e) { error = e; } @@ -577,7 +576,7 @@ export default { while(true) { let result; try { - result = await fetcher.get(`${this.apiOrigin}/api/v1/apps/${this.resourceId}`, { access_token: this.accessToken }); + result = await fetcher.get(`${API_ORIGIN}/api/v1/apps/${this.resourceId}`, { access_token: this.accessToken }); } catch (e) { console.error('Failed to fetch app status.', e); } diff --git a/frontend/src/views/Viewer.vue b/frontend/src/views/Viewer.vue index 6dcf42fec..42b32c869 100644 --- a/frontend/src/views/Viewer.vue +++ b/frontend/src/views/Viewer.vue @@ -16,7 +16,7 @@ import { TextViewer, ImageViewer } from 'pankow-viewers'; import { createDirectoryModel } from '../models/DirectoryModel.js'; import { sanitize } from 'pankow/utils'; -const API_ORIGIN = import.meta.env.VITE_API_ORIGIN ? 'https://' + import.meta.env.VITE_API_ORIGIN : ''; +const API_ORIGIN = import.meta.env.VITE_API_ORIGIN ? 'https://' + import.meta.env.VITE_API_ORIGIN : window.origin; export default { name: 'Viewer',