Backend-Adresse aus .env file beziehen

This commit is contained in:
Torsten Schulz
2024-06-15 23:29:41 +02:00
parent 61653ff407
commit 4e371f88b1
23 changed files with 568 additions and 83 deletions

View File

@@ -2,7 +2,7 @@ import axios from 'axios';
import store from './store';
import router from './router';
axios.defaults.baseURL = 'http://localhost:3000/api';
axios.defaults.baseURL = process.env.VUE_APP_BACKEND_URL;
axios.interceptors.request.use(
config => {

View File

@@ -93,9 +93,9 @@ export default {
positionIds: positionIds
};
if (this.localContactPerson.id) {
await axios.put(`http://localhost:3000/api/contact-persons/${this.localContactPerson.id}`, payload);
await axios.put(`/contact-persons/${this.localContactPerson.id}`, payload);
} else {
await axios.post('http://localhost:3000/api/contact-persons', payload);
await axios.post('/contact-persons', payload);
}
this.$emit('contactPersonSaved');

View File

@@ -175,7 +175,7 @@ export default {
},
async created() {
try {
const eventTypeResponse = await axios.get('http://localhost:3000/api/event-types');
const eventTypeResponse = await axios.get('/event-types');
this.eventTypes = eventTypeResponse.data;
this.selectedEventType = this.eventTypes.find(type => type.id === this.event.eventTypeId) || null;
} catch (error) {
@@ -196,9 +196,9 @@ export default {
payload.dayOfWeek = payload.dayOfWeek.value;
let response;
if (this.eventData.id) {
response = await axios.put(`http://localhost:3000/api/events/${this.eventData.id}`, payload);
response = await axios.put(`/events/${this.eventData.id}`, payload);
} else {
response = await axios.post('http://localhost:3000/api/events', payload);
response = await axios.post('/events', payload);
}
this.$emit('saved', response.data);
} catch (error) {

View File

@@ -89,9 +89,9 @@
async saveInstitution() {
try {
if (this.localInstitution.id) {
await axios.put(`http://localhost:3000/api/institutions/${this.localInstitution.id}`, this.localInstitution);
await axios.put(`/institutions/${this.localInstitution.id}`, this.localInstitution);
} else {
await axios.post('http://localhost:3000/api/institutions', this.localInstitution);
await axios.post('/institutions', this.localInstitution);
}
this.$emit('saved');
this.$emit('cancelled');

View File

@@ -39,10 +39,8 @@ export default {
watch: {
value(newVal) {
this.selectedPositions = newVal;
console.log('PositionSelect - value watch - newVal:', newVal);
},
selectedPositions(newVal) {
console.log('PositionSelect - selectedPositions watch - newVal:', newVal);
this.$emit('input', newVal);
}
},
@@ -52,8 +50,7 @@ export default {
methods: {
async fetchPositions() {
try {
const response = await axios.get('http://localhost:3000/api/positions');
console.log('PositionSelect - fetchPositions - response.data:', response.data);
const response = await axios.get('/positions');
this.$emit('update:options', response.data);
} catch (error) {
console.error('Fehler beim Abrufen der Positionen:', error);

View File

@@ -143,7 +143,7 @@ export default {
},
async saveMenuData() {
try {
await fetch('http://localhost:3000/api/menu-data', {
await fetch('/menu-data', {
method: 'POST',
headers: {
'Content-Type': 'application/json'

View File

@@ -45,7 +45,7 @@ export default {
methods: {
async fetchContactPersons() {
try {
const response = await axios.get('http://localhost:3000/api/contact-persons');
const response = await axios.get('/contact-persons');
this.contactPersons = response.data;
} catch (error) {
console.error('Fehler beim Abrufen der Kontaktpersonen:', error);
@@ -53,7 +53,7 @@ export default {
},
async fetchPositions() {
try {
const response = await axios.get('http://localhost:3000/api/positions');
const response = await axios.get('/positions');
this.positions = response.data;
} catch (error) {
console.error('Fehler beim Abrufen der Positionen:', error);

View File

@@ -99,7 +99,7 @@ export default {
const fetchPages = async () => {
try {
const response = await axios.get('http://localhost:3000/api/menu-data');
const response = await axios.get('/menu-data');
pages.value = response.data;
} catch (error) {
console.error('Fehler beim Abrufen der Seiten:', error);

View File

@@ -65,11 +65,11 @@ export default {
async fetchData() {
try {
const [eventResponse, institutionResponse, eventPlaceResponse, contactPersonResponse, eventTypeResponse] = await Promise.all([
axios.get('http://localhost:3000/api/events'),
axios.get('http://localhost:3000/api/institutions'),
axios.get('http://localhost:3000/api/event-places'),
axios.get('http://localhost:3000/api/contact-persons'),
axios.get('http://localhost:3000/api/event-types')
axios.get('/events'),
axios.get('/institutions'),
axios.get('/event-places'),
axios.get('/contact-persons'),
axios.get('/event-types')
]);
this.events = eventResponse.data;
@@ -91,7 +91,7 @@ export default {
},
async deleteEvent(id) {
try {
await axios.delete(`http://localhost:3000/api/events/${id}`);
await axios.delete(`/events/${id}`);
this.fetchData();
} catch (error) {
console.error('Fehler beim Löschen der Veranstaltung:', error);

View File

@@ -55,25 +55,25 @@ export default {
},
methods: {
async fetchEventPlaces() {
const response = await axios.get('http://localhost:3000/api/event-places');
const response = await axios.get('/event-places');
this.eventPlaces = response.data;
},
async addEventPlace() {
if (this.editMode) {
await axios.put(`http://localhost:3000/api/event-places/${this.editId}`, this.newEventPlace);
await axios.put(`/event-places/${this.editId}`, this.newEventPlace);
} else {
const response = await axios.post('http://localhost:3000/api/event-places', this.newEventPlace);
const response = await axios.post('/event-places', this.newEventPlace);
this.eventPlaces.push(response.data);
}
this.resetForm();
await this.fetchEventPlaces();
},
async updateEventPlace(eventPlace) {
await axios.put(`http://localhost:3000/api/event-places/${eventPlace.id}`, eventPlace);
await axios.put(`/event-places/${eventPlace.id}`, eventPlace);
this.fetchEventPlaces(); // Refresh the list
},
async deleteEventPlace(id) {
await axios.delete(`http://localhost:3000/api/event-places/${id}`);
await axios.delete(`/event-places/${id}`);
this.fetchEventPlaces(); // Refresh the list
},
editEventPlace(eventPlace) {

View File

@@ -35,7 +35,7 @@
methods: {
async fetchEventTypes() {
try {
const response = await axios.get('http://localhost:3000/api/event-types');
const response = await axios.get('/event-types');
this.eventTypes = response.data;
} catch (error) {
console.error('Fehler beim Abrufen der Event-Typen:', error);
@@ -44,9 +44,9 @@
async saveEventType() {
try {
if (this.editMode) {
await axios.put(`http://localhost:3000/api/event-types/${this.editId}`, this.eventTypeData);
await axios.put(`/event-types/${this.editId}`, this.eventTypeData);
} else {
const response = await axios.post('http://localhost:3000/api/event-types', this.eventTypeData);
const response = await axios.post('/event-types', this.eventTypeData);
this.eventTypes.push(response.data);
}
this.resetForm();
@@ -62,7 +62,7 @@
},
async deleteEventType(id) {
try {
await axios.delete(`http://localhost:3000/api/event-types/${id}`);
await axios.delete(`/event-types/${id}`);
await this.fetchEventTypes();
} catch (error) {
console.error('Fehler beim Löschen des Event-Typs:', error);

View File

@@ -77,7 +77,7 @@ export default {
methods: {
async fetchInstitutions() {
try {
const response = await axios.get('http://localhost:3000/api/institutions');
const response = await axios.get('/institutions');
this.institutions = response.data;
} catch (error) {
console.error('Fehler beim Abrufen der Institutionen:', error);
@@ -85,7 +85,7 @@ export default {
},
async fetchContactPersons() {
try {
const response = await axios.get('http://localhost:3000/api/contact-persons');
const response = await axios.get('/contact-persons');
this.contactPersons = response.data;
} catch (error) {
console.error('Fehler beim Abrufen der Kontaktpersonen:', error);
@@ -94,9 +94,9 @@ export default {
async saveInstitution() {
try {
if (this.editMode) {
await axios.put(`http://localhost:3000/api/institutions/${this.editId}`, this.institutionData);
await axios.put(`/institutions/${this.editId}`, this.institutionData);
} else {
const response = await axios.post('http://localhost:3000/api/institutions', this.institutionData);
const response = await axios.post('/institutions', this.institutionData);
this.institutions.push(response.data);
}
this.resetForm();
@@ -113,7 +113,7 @@ export default {
},
async deleteInstitution(id) {
try {
await axios.delete(`http://localhost:3000/api/institutions/${id}`);
await axios.delete(`/institutions/${id}`);
this.fetchInstitutions();
} catch (error) {
console.error('Fehler beim Löschen der Institution:', error);

View File

@@ -43,25 +43,25 @@ export default {
},
methods: {
async fetchPositions() {
const response = await axios.get('http://localhost:3000/api/positions');
const response = await axios.get('/positions');
this.positions = response.data;
},
async addPosition() {
if (this.editMode) {
await axios.put(`http://localhost:3000/api/positions/${this.editId}`, this.newPosition);
await axios.put(`/positions/${this.editId}`, this.newPosition);
} else {
const response = await axios.post('http://localhost:3000/api/positions', this.newPosition);
const response = await axios.post('/positions', this.newPosition);
this.positions.push(response.data);
}
this.resetForm();
await this.fetchPositions();
},
async updatePosition(position) {
await axios.put(`http://localhost:3000/api/positions/${position.id}`, position);
await axios.put(`/positions/${position.id}`, position);
this.fetchPositions(); // Refresh the list
},
async deletePosition(id) {
await axios.delete(`http://localhost:3000/api/positions/${id}`);
await axios.delete(`/positions/${id}`);
this.fetchPositions(); // Refresh the list
},
editPosition(position) {

View File

@@ -90,7 +90,7 @@ export default {
formatDate,
async fetchWorships() {
try {
const response = await axios.get('http://localhost:3000/api/worships');
const response = await axios.get('/worships');
this.worships = response.data;
} catch (error) {
console.error('Fehler beim Abrufen der Gottesdienste:', error);
@@ -98,7 +98,7 @@ export default {
},
async fetchEventPlaces() {
try {
const response = await axios.get('http://localhost:3000/api/event-places');
const response = await axios.get('/event-places');
this.eventPlaces = response.data;
} catch (error) {
console.error('Fehler beim Abrufen der Veranstaltungsorte:', error);
@@ -112,9 +112,9 @@ export default {
};
if (this.editMode) {
await axios.put(`http://localhost:3000/api/worships/${this.editId}`, payload);
await axios.put(`/worships/${this.editId}`, payload);
} else {
await axios.post('http://localhost:3000/api/worships', payload);
await axios.post('/worships', payload);
}
this.resetForm();
@@ -131,7 +131,7 @@ export default {
},
async deleteWorship(id) {
try {
await axios.delete(`http://localhost:3000/api/worships/${id}`);
await axios.delete(`/worships/${id}`);
await this.fetchWorships();
} catch (error) {
console.error('Fehler beim Löschen des Gottesdienstes:', error);

View File

@@ -48,22 +48,15 @@ export default {
...mapActions(['login']),
async runLogin() {
try {
const response = await axios.post('http://localhost:3000/api/auth/login', {
const response = await axios.post('/auth/login', {
email: this.email,
password: this.password
});
console.log(1);
const token = response.data.token;
console.log(2);
const data = response.data;
console.log(3);
localStorage.setItem('token', token);
console.log(4);
console.log(data);
this.login(data.user);
console.log(5);
axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
console.log(6);
this.$router.push('/admin');
} catch (error) {
if (error.response) {

View File

@@ -2,16 +2,16 @@ import { createApp } from 'vue';
import AppComponent from './AppComponent.vue';
import router from './router';
import store from './store';
import axios from './axios'; // Korrigieren Sie den Import-Pfad hier
import './assets/css/editor.css'; // Hier deine CSS-Datei einbinden
import axios from './axios';
import './assets/css/editor.css';
async function fetchMenuData() {
const response = await fetch('http://localhost:3000/api/menu-data');
return await response.json();
const response = await fetch(process.env.VUE_APP_BACKEND_URL + '/menu-data');
return await response.json();
}
fetchMenuData().then(menuData => {
store.commit('setMenuData', menuData);
store.commit('setMenuData', menuData);
});
const app = createApp(AppComponent);

View File

@@ -19,19 +19,12 @@ export default createStore({
},
mutations: {
setLogin(state, { user, token }) {
console.log(1);
state.isLoggedIn = true;
console.log(2);
state.user = user;
console.log(3);
state.token = token;
console.log(4);
localStorage.setItem('isLoggedIn', 'true');
console.log(5);
localStorage.setItem('user', JSON.stringify(user));
console.log(6);
localStorage.setItem('token', token);
console.log(7);
},
logout(state) {
state.isLoggedIn = false;
@@ -55,7 +48,7 @@ export default createStore({
actions: {
async loadMenuData({ commit }) {
try {
const response = await fetch('http://localhost:3000/api/menu-data');
const response = await fetch('/menu-data');
const menuData = await response.json();
commit('setMenuData', menuData);
} catch (error) {
@@ -64,7 +57,7 @@ export default createStore({
},
async loadPageContent({ commit }, link) {
try {
const response = await axios.get(`http://localhost:3000/api/page-content?link=${link}`);
const response = await axios.get(`/page-content?link=${link}`);
commit('SET_PAGE_CONTENT', response.data.content || '');
} catch (error) {
console.error('Fehler beim Laden des Seiteninhalts:', error);
@@ -74,7 +67,7 @@ export default createStore({
try {
const contentToSave = state.pageContent;
await axios.post('http://localhost:3000/api/page-content', {
await axios.post('/page-content', {
link,
name,
content: contentToSave,
@@ -86,7 +79,6 @@ export default createStore({
}
},
login({ commit }, { user, token }) {
console.log('do login');
commit('setLogin', { user, token });
},
logout({ commit }) {