frontend: ensure API_ORIGIN is always set
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user