Aktualisiere die Axios-Konfiguration: Setze die Basis-URL standardmäßig auf '/api' und ermögliche die Verwendung einer Umgebungsvariablen in Entwicklungsumgebungen. Verhindere Mixed-Content-Probleme durch Umstellung auf HTTPS. Ändere den Import von Axios im Store, um die neue Konfiguration zu nutzen.

This commit is contained in:
Torsten Schulz (local)
2025-11-22 22:23:08 +01:00
parent 718bcabea3
commit 550ed97a11
2 changed files with 17 additions and 4 deletions

View File

@@ -3,11 +3,24 @@ import store from './store';
import router from './router';
// Basis-URL für das Backend ermitteln
let baseURL = process.env.VUE_APP_BACKEND_URL || '/api';
// Standard: gleiche Origin unter dem Pfad "/api"
let baseURL = '/api';
// Nur in Entwicklungsumgebungen (localhost / torstens) eine explizite Backend-URL aus .env benutzen
if (typeof window !== 'undefined') {
const hostname = window.location.hostname;
const isDevHost =
hostname === 'localhost' ||
hostname === '127.0.0.1' ||
hostname === '::1' ||
hostname === 'torstens';
if (isDevHost && process.env.VUE_APP_BACKEND_URL) {
baseURL = process.env.VUE_APP_BACKEND_URL;
}
// Mixed-Content vermeiden: wenn die Seite über HTTPS läuft,
// aber die Konfiguration "http://" verwendet, auf "https://" umschalten.
if (typeof window !== 'undefined') {
const isHttps = window.location.protocol === 'https:';
if (isHttps && baseURL.startsWith('http://')) {
baseURL = baseURL.replace(/^http:/, 'https:');

View File

@@ -1,5 +1,5 @@
import { createStore } from 'vuex';
import axios from 'axios';
import axios from '../axios';
import router from '../router';
let user = [];