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:
17
src/axios.js
17
src/axios.js
@@ -3,11 +3,24 @@ import store from './store';
|
|||||||
import router from './router';
|
import router from './router';
|
||||||
|
|
||||||
// Basis-URL für das Backend ermitteln
|
// 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,
|
// Mixed-Content vermeiden: wenn die Seite über HTTPS läuft,
|
||||||
// aber die Konfiguration "http://" verwendet, auf "https://" umschalten.
|
// aber die Konfiguration "http://" verwendet, auf "https://" umschalten.
|
||||||
if (typeof window !== 'undefined') {
|
|
||||||
const isHttps = window.location.protocol === 'https:';
|
const isHttps = window.location.protocol === 'https:';
|
||||||
if (isHttps && baseURL.startsWith('http://')) {
|
if (isHttps && baseURL.startsWith('http://')) {
|
||||||
baseURL = baseURL.replace(/^http:/, 'https:');
|
baseURL = baseURL.replace(/^http:/, 'https:');
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createStore } from 'vuex';
|
import { createStore } from 'vuex';
|
||||||
import axios from 'axios';
|
import axios from '../axios';
|
||||||
import router from '../router';
|
import router from '../router';
|
||||||
|
|
||||||
let user = [];
|
let user = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user