fix: Fix API paths in Dictionary template for Traefik routing
- API calls were using absolute paths (/api/words) but container runs under path prefix
- Added apiBase variable to extract current pathname
- All fetch calls now use relative paths: ${apiBase}/api/words
- Fixes 404 errors when accessing Dictionary template through Traefik
This commit is contained in:
parent
06f34cdc6a
commit
20a4d60f21
|
|
@ -419,6 +419,9 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
// API Base Path (einbeziehen aktuellen Pfad für Traefik Routing)
|
||||||
|
const apiBase = window.location.pathname.replace(/\/$/, '');
|
||||||
|
|
||||||
// State Management
|
// State Management
|
||||||
let words = [];
|
let words = [];
|
||||||
let isLoading = false;
|
let isLoading = false;
|
||||||
|
|
@ -442,7 +445,7 @@
|
||||||
wordsList.innerHTML = '<div class="loading"><div class="spinner"></div></div>';
|
wordsList.innerHTML = '<div class="loading"><div class="spinner"></div></div>';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/words');
|
const response = await fetch(`${apiBase}/api/words`);
|
||||||
if (!response.ok) throw new Error('Fehler beim Laden');
|
if (!response.ok) throw new Error('Fehler beim Laden');
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
@ -494,7 +497,7 @@
|
||||||
btn.textContent = 'Wird gespeichert...';
|
btn.textContent = 'Wird gespeichert...';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/words', {
|
const response = await fetch(`${apiBase}/api/words`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
|
|
@ -526,7 +529,7 @@
|
||||||
if (!confirm('Wort wirklich löschen?')) return;
|
if (!confirm('Wort wirklich löschen?')) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/words/${id}`, {
|
const response = await fetch(`${apiBase}/api/words/${id}`, {
|
||||||
method: 'DELETE'
|
method: 'DELETE'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user