Files
picpeak/frontend/src/pages/public/LegalPage.tsx
T
paul ac1cd96ecd
Test and Lint / backend-test (push) Successful in 1m16s
continuous-integration/drone/push Build is failing
Test and Lint / frontend-test (push) Successful in 2m18s
Version and Release / version-bump (push) Successful in 43s
Version and Release / trigger-drone (push) Successful in 4s
fix: resolve frontend API routing issues for Traefik deployment
Major fixes for production deployment with Traefik:

1. API Path Fixes:
   - Remove double /api prefix from all frontend service calls
   - Fix auth.service.ts to use correct paths (/auth/admin/login)
   - Update all services to use single /api prefix from base URL
   - Fix template literal paths in photo services

2. Docker Configuration:
   - Add build args for VITE_API_URL in docker-compose.prod.yml
   - Create Dockerfile.prod with proper API URL configuration
   - Ensure frontend is built with correct API base path

3. Documentation:
   - Add comprehensive TRAEFIK_DEPLOYMENT.md guide
   - Document proper Traefik labels and routing configuration
   - Include troubleshooting steps for common issues
   - Explain network configuration and SSL handling

This resolves:
- 502 Bad Gateway errors
- Double /api/api paths in requests
- Frontend unable to communicate with backend
- Login functionality not working

The frontend now correctly calls the backend API through Traefik's
routing, with all requests going to /api/* being forwarded to the
backend service on port 3000.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-13 23:18:00 +02:00

139 lines
4.5 KiB
TypeScript

import React, { useEffect } from 'react';
import { useParams, Link, useNavigate } from 'react-router-dom';
import { useQuery } from '@tanstack/react-query';
import { useTranslation } from 'react-i18next';
import { ArrowLeft, Home } from 'lucide-react';
import DOMPurify from 'dompurify';
import { Loading, Card } from '../../components/common';
import { cmsService } from '../../services/cms.service';
import { api } from '../../config/api';
export const LegalPage: React.FC = () => {
const { slug } = useParams<{ slug: string }>();
const { i18n } = useTranslation();
const navigate = useNavigate();
// Extract page slug from pathname if not in params (for static routes like /impressum)
const pathname = window.location.pathname;
const pageSlug = slug || pathname.split('/').pop() || '';
// Fetch settings to get default language
const { data: settingsData } = useQuery({
queryKey: ['public-settings'],
queryFn: async () => {
const response = await api.get('/public/settings');
return response.data;
},
staleTime: 5 * 60 * 1000, // Cache for 5 minutes
});
// Use admin settings language
const lang = settingsData?.default_language || 'en';
// Fetch page content
const { data: page, isLoading, error } = useQuery({
queryKey: ['legal-page', pageSlug, lang],
queryFn: () => cmsService.getPublicPage(pageSlug, lang),
enabled: !!pageSlug && pageSlug !== '' && !!settingsData,
});
// Set i18n language when settings are loaded
useEffect(() => {
if (settingsData?.default_language) {
i18n.changeLanguage(settingsData.default_language);
}
}, [settingsData, i18n]);
// Update page title
useEffect(() => {
if (page?.title) {
document.title = `${page.title} - PicPeak`;
}
}, [page?.title]);
if (isLoading) {
return (
<div className="min-h-screen bg-neutral-50 flex items-center justify-center">
<Loading size="lg" text="Loading..." />
</div>
);
}
if (error || !page) {
return (
<div className="min-h-screen bg-neutral-50 flex items-center justify-center">
<Card className="max-w-md w-full mx-4">
<div className="text-center py-12 px-6">
<h2 className="text-xl font-semibold mb-2">Page Not Found</h2>
<p className="text-neutral-600 mb-6">
The page you're looking for doesn't exist.
</p>
<Link
to="/"
className="inline-flex items-center gap-2 text-primary-600 hover:text-primary-700"
>
<Home className="w-4 h-4" />
Go to Homepage
</Link>
</div>
</Card>
</div>
);
}
return (
<div className="min-h-screen bg-neutral-50">
{/* Header */}
<header className="bg-white border-b border-neutral-200">
<div className="container py-4">
<button
onClick={() => navigate(-1)}
className="inline-flex items-center gap-2 text-neutral-600 hover:text-neutral-900 transition-colors"
>
<ArrowLeft className="w-4 h-4" />
{i18n.language === 'de' ? 'Zurück' : 'Back'}
</button>
</div>
</header>
{/* Content */}
<main className="container py-12">
<div className="max-w-4xl mx-auto">
<Card padding="lg">
<h1 className="text-3xl font-bold text-neutral-900 mb-8">{page.title}</h1>
<div
className="prose prose-neutral max-w-none"
dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(page.content) }}
/>
</Card>
</div>
</main>
{/* Footer */}
<footer className="mt-auto py-8 border-t border-neutral-200">
<div className="container text-center">
<div className="flex justify-center gap-4 text-sm">
<Link
to="/impressum"
className="text-neutral-600 hover:text-neutral-900"
>
{lang === 'de' ? 'Impressum' : 'Legal Notice'}
</Link>
<span className="text-neutral-400"></span>
<Link
to="/datenschutz"
className="text-neutral-600 hover:text-neutral-900"
>
{lang === 'de' ? 'Datenschutz' : 'Privacy Policy'}
</Link>
</div>
<p className="text-sm text-neutral-500 mt-4">
© 2024 PicPeak. All rights reserved.
</p>
</div>
</footer>
</div>
);
};