diff --git a/src/axios.js b/src/axios.js index cad0540..1bc3dae 100644 --- a/src/axios.js +++ b/src/axios.js @@ -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'; -// Mixed-Content vermeiden: wenn die Seite über HTTPS läuft, -// aber die Konfiguration "http://" verwendet, auf "https://" umschalten. +// 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. const isHttps = window.location.protocol === 'https:'; if (isHttps && baseURL.startsWith('http://')) { baseURL = baseURL.replace(/^http:/, 'https:'); diff --git a/src/store/index.js b/src/store/index.js index c81ecc5..9bf4ce3 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,5 +1,5 @@ import { createStore } from 'vuex'; -import axios from 'axios'; +import axios from '../axios'; import router from '../router'; let user = [];