2 Commits

Author SHA1 Message Date
denshooter
ede591c89e Fix ActivityFeed hydration error: Move localStorage read to useEffect to prevent server/client mismatch
All checks were successful
Production Deployment (Zero Downtime) / deploy-production (push) Successful in 12m10s
2026-01-10 18:28:25 +01:00
denshooter
2defd7a4a9 Fix ActivityFeed: Remove dynamic import that was causing it to disappear in production
Some checks failed
Production Deployment (Zero Downtime) / deploy-production (push) Has been cancelled
2026-01-10 18:16:01 +01:00
134 changed files with 3258 additions and 8384 deletions

View File

@@ -57,7 +57,6 @@ docker-compose*.yml
# Scripts (keep only essential ones) # Scripts (keep only essential ones)
scripts scripts
!scripts/init-db.sql !scripts/init-db.sql
!scripts/start-with-migrate.js
# Misc # Misc
.cache .cache

View File

@@ -7,11 +7,11 @@ on:
env: env:
NODE_VERSION: '20' NODE_VERSION: '20'
DOCKER_IMAGE: portfolio-app DOCKER_IMAGE: portfolio-app
IMAGE_TAG: dev IMAGE_TAG: staging
jobs: jobs:
deploy-dev: deploy-dev:
runs-on: ubuntu-latest # Gitea Actions: Use runner with ubuntu-latest label runs-on: ubuntu-latest
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v3 uses: actions/checkout@v3
@@ -50,210 +50,31 @@ jobs:
run: | run: |
echo "🚀 Starting zero-downtime dev deployment..." echo "🚀 Starting zero-downtime dev deployment..."
CONTAINER_NAME="portfolio-app-dev" COMPOSE_FILE="docker-compose.staging.yml"
HEALTH_PORT="3001" CONTAINER_NAME="portfolio-app-staging"
IMAGE_NAME="${{ env.DOCKER_IMAGE }}:${{ env.IMAGE_TAG }}" HEALTH_PORT="3002"
# Check for existing container (running or stopped) # Backup current container ID if running
EXISTING_CONTAINER=$(docker ps -aq -f name=$CONTAINER_NAME || echo "") OLD_CONTAINER=$(docker ps -q -f name=$CONTAINER_NAME || echo "")
# Start DB and Redis if not running
echo "🗄️ Starting database and Redis..."
COMPOSE_FILE="docker-compose.dev.minimal.yml"
# Stop and remove existing containers to ensure clean start with correct architecture
echo "🧹 Cleaning up existing containers..."
docker stop portfolio_postgres_dev portfolio_redis_dev 2>/dev/null || true
docker rm portfolio_postgres_dev portfolio_redis_dev 2>/dev/null || true
# Remove old images to force re-pull with correct architecture
echo "🔄 Removing old images to force re-pull..."
docker rmi postgres:15-alpine redis:7-alpine 2>/dev/null || true
# Pull images with correct architecture (Docker will auto-detect)
echo "📥 Pulling images for current architecture..."
docker compose -f $COMPOSE_FILE pull postgres redis
# Start containers
echo "📦 Starting PostgreSQL and Redis containers..."
docker compose -f $COMPOSE_FILE up -d postgres redis
# Wait for DB to be ready
echo "⏳ Waiting for database to be ready..."
for i in {1..30}; do
if docker exec portfolio_postgres_dev pg_isready -U portfolio_user -d portfolio_dev >/dev/null 2>&1; then
echo "✅ Database is ready!"
break
fi
echo "⏳ Waiting for database... ($i/30)"
sleep 1
done
# Export environment variables
export NODE_ENV=production
export LOG_LEVEL=${LOG_LEVEL:-debug}
export NEXT_PUBLIC_BASE_URL=${NEXT_PUBLIC_BASE_URL_DEV:-https://dev.dk0.dev}
export DATABASE_URL="postgresql://portfolio_user:portfolio_dev_pass@portfolio_postgres_dev:5432/portfolio_dev?schema=public"
export REDIS_URL="redis://portfolio_redis_dev:6379"
export MY_EMAIL=${MY_EMAIL}
export MY_INFO_EMAIL=${MY_INFO_EMAIL}
export MY_PASSWORD=${MY_PASSWORD}
export MY_INFO_PASSWORD=${MY_INFO_PASSWORD}
export ADMIN_BASIC_AUTH=${ADMIN_BASIC_AUTH}
export ADMIN_SESSION_SECRET=${ADMIN_SESSION_SECRET}
export N8N_WEBHOOK_URL=${N8N_WEBHOOK_URL:-''}
export N8N_SECRET_TOKEN=${N8N_SECRET_TOKEN:-''}
export PORT=${HEALTH_PORT}
# Stop and remove existing container if it exists (running or stopped)
if [ ! -z "$EXISTING_CONTAINER" ]; then
echo "🛑 Stopping and removing existing container..."
docker stop $EXISTING_CONTAINER 2>/dev/null || true
docker rm $EXISTING_CONTAINER 2>/dev/null || true
echo "✅ Old container removed"
# Wait for Docker to release the port
echo "⏳ Waiting for Docker to release port ${HEALTH_PORT}..."
sleep 3
fi
# Check if port is still in use by Docker containers (check all containers, not just running)
PORT_CONTAINER=$(docker ps -a --format "{{.ID}}\t{{.Names}}\t{{.Ports}}" | grep -E "(:${HEALTH_PORT}->|:${HEALTH_PORT}/)" | awk '{print $1}' | head -1 || echo "")
if [ ! -z "$PORT_CONTAINER" ]; then
echo "⚠️ Port ${HEALTH_PORT} is still in use by container $PORT_CONTAINER"
echo "🛑 Stopping and removing container using port..."
docker stop $PORT_CONTAINER 2>/dev/null || true
docker rm $PORT_CONTAINER 2>/dev/null || true
sleep 3
fi
# Also check for any containers with the same name that might be using the port
SAME_NAME_CONTAINER=$(docker ps -a -q -f name=$CONTAINER_NAME | head -1 || echo "")
if [ ! -z "$SAME_NAME_CONTAINER" ] && [ "$SAME_NAME_CONTAINER" != "$EXISTING_CONTAINER" ]; then
echo "⚠️ Found another container with same name: $SAME_NAME_CONTAINER"
docker stop $SAME_NAME_CONTAINER 2>/dev/null || true
docker rm $SAME_NAME_CONTAINER 2>/dev/null || true
sleep 2
fi
# Also check if port is in use by another process (non-Docker)
PORT_IN_USE=$(lsof -ti:${HEALTH_PORT} 2>/dev/null || ss -tlnp | grep ":${HEALTH_PORT} " | head -1 || echo "")
if [ ! -z "$PORT_IN_USE" ] && [ -z "$PORT_CONTAINER" ]; then
echo "⚠️ Port ${HEALTH_PORT} is in use by process"
echo "Attempting to free the port..."
# Try to find and kill the process
if command -v lsof >/dev/null 2>&1; then
PID=$(lsof -ti:${HEALTH_PORT} 2>/dev/null || echo "")
if [ ! -z "$PID" ]; then
kill -9 $PID 2>/dev/null || true
sleep 2
fi
fi
fi
# Final check: verify port is free and wait if needed
echo "🔍 Verifying port ${HEALTH_PORT} is free..."
MAX_WAIT=10
WAIT_COUNT=0
while [ $WAIT_COUNT -lt $MAX_WAIT ]; do
PORT_CHECK=$(docker ps --format "{{.Ports}}" | grep -E "(:${HEALTH_PORT}->|:${HEALTH_PORT}/)" || echo "")
if [ -z "$PORT_CHECK" ]; then
# Also check with lsof/ss if available
if command -v lsof >/dev/null 2>&1; then
PORT_CHECK=$(lsof -ti:${HEALTH_PORT} 2>/dev/null || echo "")
elif command -v ss >/dev/null 2>&1; then
PORT_CHECK=$(ss -tlnp | grep ":${HEALTH_PORT} " || echo "")
fi
fi
if [ -z "$PORT_CHECK" ]; then
echo "✅ Port ${HEALTH_PORT} is free!"
break
fi
WAIT_COUNT=$((WAIT_COUNT + 1))
echo "⏳ Port still in use, waiting... ($WAIT_COUNT/$MAX_WAIT)"
sleep 1
done
# If port is still in use, try alternative port
if [ $WAIT_COUNT -ge $MAX_WAIT ]; then
echo "⚠️ Port ${HEALTH_PORT} is still in use after waiting. Trying alternative port..."
HEALTH_PORT="3002"
echo "🔄 Using alternative port: ${HEALTH_PORT}"
# Quick check if alternative port is also in use
ALT_PORT_CHECK=$(docker ps --format "{{.Ports}}" | grep -E "(:${HEALTH_PORT}->|:${HEALTH_PORT}/)" || echo "")
if [ ! -z "$ALT_PORT_CHECK" ]; then
echo "❌ Alternative port ${HEALTH_PORT} is also in use!"
echo "Attempting to free alternative port..."
ALT_CONTAINER=$(docker ps -a --format "{{.ID}}\t{{.Names}}\t{{.Ports}}" | grep -E "(:${HEALTH_PORT}->|:${HEALTH_PORT}/)" | awk '{print $1}' | head -1 || echo "")
if [ ! -z "$ALT_CONTAINER" ]; then
docker stop $ALT_CONTAINER 2>/dev/null || true
docker rm $ALT_CONTAINER 2>/dev/null || true
sleep 2
fi
fi
fi
# Ensure networks exist
echo "🌐 Checking for networks..."
if ! docker network inspect proxy >/dev/null 2>&1; then
echo "⚠️ Proxy network not found, creating it..."
docker network create proxy 2>/dev/null || echo "Network might already exist or creation failed"
else
echo "✅ Proxy network exists"
fi
if ! docker network inspect portfolio_dev >/dev/null 2>&1; then
echo "⚠️ Portfolio dev network not found, creating it..."
docker network create portfolio_dev 2>/dev/null || echo "Network might already exist or creation failed"
else
echo "✅ Portfolio dev network exists"
fi
# Connect proxy network to portfolio_dev network if needed
# (This allows the app to access both proxy and DB/Redis)
# Start new container with updated image # Start new container with updated image
echo "🆕 Starting new dev container..." echo "🆕 Starting new dev container..."
docker run -d \ docker compose -f $COMPOSE_FILE up -d --no-deps --build portfolio-staging
--name $CONTAINER_NAME \
--restart unless-stopped \
--network portfolio_dev \
-p ${HEALTH_PORT}:3000 \
-e NODE_ENV=production \
-e LOG_LEVEL=${LOG_LEVEL:-debug} \
-e NEXT_PUBLIC_BASE_URL=${NEXT_PUBLIC_BASE_URL_DEV:-https://dev.dk0.dev} \
-e DATABASE_URL=${DATABASE_URL} \
-e REDIS_URL=${REDIS_URL} \
-e MY_EMAIL=${MY_EMAIL} \
-e MY_INFO_EMAIL=${MY_INFO_EMAIL} \
-e MY_PASSWORD=${MY_PASSWORD} \
-e MY_INFO_PASSWORD=${MY_INFO_PASSWORD} \
-e ADMIN_BASIC_AUTH=${ADMIN_BASIC_AUTH} \
-e ADMIN_SESSION_SECRET=${ADMIN_SESSION_SECRET} \
-e N8N_WEBHOOK_URL=${N8N_WEBHOOK_URL:-''} \
-e N8N_SECRET_TOKEN=${N8N_SECRET_TOKEN:-''} \
$IMAGE_NAME
# Connect container to proxy network as well (for external access)
echo "🔗 Connecting container to proxy network..."
docker network connect proxy $CONTAINER_NAME 2>/dev/null || echo "Container might already be connected to proxy network"
# Wait for new container to be healthy # Wait for new container to be healthy
echo "⏳ Waiting for new container to be healthy..." echo "⏳ Waiting for new container to be healthy..."
HEALTH_CHECK_PASSED=false
for i in {1..60}; do for i in {1..60}; do
NEW_CONTAINER=$(docker ps -q -f name=$CONTAINER_NAME) NEW_CONTAINER=$(docker ps -q -f name=$CONTAINER_NAME)
if [ ! -z "$NEW_CONTAINER" ]; then if [ ! -z "$NEW_CONTAINER" ]; then
# Check Docker health status # Check health status
HEALTH=$(docker inspect $NEW_CONTAINER --format='{{.State.Health.Status}}' 2>/dev/null || echo "starting") HEALTH=$(docker inspect $NEW_CONTAINER --format='{{.State.Health.Status}}' 2>/dev/null || echo "starting")
if [ "$HEALTH" == "healthy" ]; then if [ "$HEALTH" == "healthy" ]; then
echo "✅ New container is healthy!" echo "✅ New container is healthy!"
HEALTH_CHECK_PASSED=true
break break
fi fi
# Also check HTTP health endpoint # Also check HTTP health endpoint
if curl -f http://localhost:$HEALTH_PORT/api/health > /dev/null 2>&1; then if curl -f http://localhost:$HEALTH_PORT/api/health > /dev/null 2>&1; then
echo "✅ New container is responding!" echo "✅ New container is responding!"
HEALTH_CHECK_PASSED=true
break break
fi fi
fi fi
@@ -262,9 +83,9 @@ jobs:
done done
# Verify new container is working # Verify new container is working
if [ "$HEALTH_CHECK_PASSED" != "true" ]; then if ! curl -f http://localhost:$HEALTH_PORT/api/health > /dev/null 2>&1; then
echo "⚠️ New dev container health check failed, but continuing (non-blocking)..." echo "⚠️ New dev container health check failed, but continuing (non-blocking)..."
docker logs $CONTAINER_NAME --tail=50 docker compose -f $COMPOSE_FILE logs --tail=50 portfolio-staging
fi fi
# Remove old container if it exists and is different # Remove old container if it exists and is different
@@ -279,17 +100,14 @@ jobs:
echo "✅ Dev deployment completed!" echo "✅ Dev deployment completed!"
env: env:
NODE_ENV: production NODE_ENV: staging
LOG_LEVEL: ${{ vars.LOG_LEVEL || 'debug' }} LOG_LEVEL: ${{ vars.LOG_LEVEL || 'debug' }}
NEXT_PUBLIC_BASE_URL_DEV: ${{ vars.NEXT_PUBLIC_BASE_URL_DEV || 'https://dev.dk0.dev' }} NEXT_PUBLIC_BASE_URL: ${{ vars.NEXT_PUBLIC_BASE_URL || 'https://dev.dk0.dev' }}
DATABASE_URL: postgresql://portfolio_user:portfolio_dev_pass@portfolio_postgres_dev:5432/portfolio_dev?schema=public
REDIS_URL: redis://portfolio_redis_dev:6379
MY_EMAIL: ${{ vars.MY_EMAIL }} MY_EMAIL: ${{ vars.MY_EMAIL }}
MY_INFO_EMAIL: ${{ vars.MY_INFO_EMAIL }} MY_INFO_EMAIL: ${{ vars.MY_INFO_EMAIL }}
MY_PASSWORD: ${{ secrets.MY_PASSWORD }} MY_PASSWORD: ${{ secrets.MY_PASSWORD }}
MY_INFO_PASSWORD: ${{ secrets.MY_INFO_PASSWORD }} MY_INFO_PASSWORD: ${{ secrets.MY_INFO_PASSWORD }}
ADMIN_BASIC_AUTH: ${{ secrets.ADMIN_BASIC_AUTH }} ADMIN_BASIC_AUTH: ${{ secrets.ADMIN_BASIC_AUTH }}
ADMIN_SESSION_SECRET: ${{ secrets.ADMIN_SESSION_SECRET }}
N8N_WEBHOOK_URL: ${{ vars.N8N_WEBHOOK_URL || '' }} N8N_WEBHOOK_URL: ${{ vars.N8N_WEBHOOK_URL || '' }}
N8N_SECRET_TOKEN: ${{ secrets.N8N_SECRET_TOKEN || '' }} N8N_SECRET_TOKEN: ${{ secrets.N8N_SECRET_TOKEN || '' }}
@@ -297,7 +115,7 @@ jobs:
run: | run: |
echo "🔍 Running dev health checks..." echo "🔍 Running dev health checks..."
for i in {1..20}; do for i in {1..20}; do
if curl -f http://localhost:3001/api/health && curl -f http://localhost:3001/ > /dev/null; then if curl -f http://localhost:3002/api/health && curl -f http://localhost:3002/ > /dev/null; then
echo "✅ Dev is fully operational!" echo "✅ Dev is fully operational!"
exit 0 exit 0
fi fi
@@ -305,7 +123,7 @@ jobs:
sleep 3 sleep 3
done done
echo "⚠️ Dev health check failed, but continuing (non-blocking)..." echo "⚠️ Dev health check failed, but continuing (non-blocking)..."
docker logs portfolio-app-dev --tail=50 docker compose -f docker-compose.staging.yml logs --tail=50
- name: Cleanup - name: Cleanup
run: | run: |

View File

@@ -11,7 +11,7 @@ env:
jobs: jobs:
deploy-production: deploy-production:
runs-on: ubuntu-latest # Gitea Actions: Use runner with ubuntu-latest label runs-on: ubuntu-latest
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v3 uses: actions/checkout@v3
@@ -69,7 +69,6 @@ jobs:
export MY_PASSWORD="${{ secrets.MY_PASSWORD }}" export MY_PASSWORD="${{ secrets.MY_PASSWORD }}"
export MY_INFO_PASSWORD="${{ secrets.MY_INFO_PASSWORD }}" export MY_INFO_PASSWORD="${{ secrets.MY_INFO_PASSWORD }}"
export ADMIN_BASIC_AUTH="${{ secrets.ADMIN_BASIC_AUTH }}" export ADMIN_BASIC_AUTH="${{ secrets.ADMIN_BASIC_AUTH }}"
export ADMIN_SESSION_SECRET="${{ secrets.ADMIN_SESSION_SECRET }}"
# Start new container with updated image (docker-compose will handle this) # Start new container with updated image (docker-compose will handle this)
echo "🆕 Starting new production container..." echo "🆕 Starting new production container..."
@@ -197,13 +196,12 @@ jobs:
env: env:
NODE_ENV: production NODE_ENV: production
LOG_LEVEL: ${{ vars.LOG_LEVEL || 'info' }} LOG_LEVEL: ${{ vars.LOG_LEVEL || 'info' }}
NEXT_PUBLIC_BASE_URL: ${{ vars.NEXT_PUBLIC_BASE_URL_PRODUCTION || 'https://dk0.dev' }} NEXT_PUBLIC_BASE_URL: ${{ vars.NEXT_PUBLIC_BASE_URL || 'https://dk0.dev' }}
MY_EMAIL: ${{ vars.MY_EMAIL }} MY_EMAIL: ${{ vars.MY_EMAIL }}
MY_INFO_EMAIL: ${{ vars.MY_INFO_EMAIL }} MY_INFO_EMAIL: ${{ vars.MY_INFO_EMAIL }}
MY_PASSWORD: ${{ secrets.MY_PASSWORD }} MY_PASSWORD: ${{ secrets.MY_PASSWORD }}
MY_INFO_PASSWORD: ${{ secrets.MY_INFO_PASSWORD }} MY_INFO_PASSWORD: ${{ secrets.MY_INFO_PASSWORD }}
ADMIN_BASIC_AUTH: ${{ secrets.ADMIN_BASIC_AUTH }} ADMIN_BASIC_AUTH: ${{ secrets.ADMIN_BASIC_AUTH }}
ADMIN_SESSION_SECRET: ${{ secrets.ADMIN_SESSION_SECRET }}
N8N_WEBHOOK_URL: ${{ vars.N8N_WEBHOOK_URL || '' }} N8N_WEBHOOK_URL: ${{ vars.N8N_WEBHOOK_URL || '' }}
N8N_SECRET_TOKEN: ${{ secrets.N8N_SECRET_TOKEN || '' }} N8N_SECRET_TOKEN: ${{ secrets.N8N_SECRET_TOKEN || '' }}
N8N_API_KEY: ${{ vars.N8N_API_KEY || '' }} N8N_API_KEY: ${{ vars.N8N_API_KEY || '' }}

200
DEPLOYMENT_SETUP.md Normal file
View File

@@ -0,0 +1,200 @@
# 🚀 Deployment Setup Guide
## Overview
This project uses a **dual-branch deployment strategy** with zero-downtime deployments:
- **Production Branch** (`production`) → Serves `https://dk0.dev` on port 3000
- **Dev Branch** (`dev`) → Serves `https://dev.dk0.dev` on port 3002
Both environments are completely isolated with separate:
- Docker containers
- Databases (PostgreSQL)
- Redis instances
- Networks
- Volumes
## Branch Strategy
### Production Branch
- **Branch**: `production`
- **Domain**: `https://dk0.dev`
- **Port**: `3000`
- **Container**: `portfolio-app`
- **Database**: `portfolio_db` (port 5432)
- **Redis**: `portfolio-redis` (port 6379)
- **Image Tag**: `portfolio-app:production` / `portfolio-app:latest`
### Dev Branch
- **Branch**: `dev`
- **Domain**: `https://dev.dk0.dev`
- **Port**: `3002`
- **Container**: `portfolio-app-staging`
- **Database**: `portfolio_staging_db` (port 5434)
- **Redis**: `portfolio-redis-staging` (port 6381)
- **Image Tag**: `portfolio-app:staging`
## Automatic Deployment
### How It Works
1. **Push to `production` branch**:
- Triggers `.gitea/workflows/production-deploy.yml`
- Runs tests, builds, and deploys to production
- Zero-downtime deployment (starts new container, waits for health, removes old)
2. **Push to `dev` branch**:
- Triggers `.gitea/workflows/dev-deploy.yml`
- Runs tests, builds, and deploys to dev/staging
- Zero-downtime deployment
### Zero-Downtime Process
1. Build new Docker image
2. Start new container with updated image
3. Wait for new container to be healthy (health checks)
4. Verify HTTP endpoints respond correctly
5. Remove old container (if different)
6. Cleanup old images
## Manual Deployment
### Production
```bash
# Build and deploy production
docker build -t portfolio-app:latest .
docker compose -f docker-compose.production.yml up -d --build
```
### Dev/Staging
```bash
# Build and deploy dev
docker build -t portfolio-app:staging .
docker compose -f docker-compose.staging.yml up -d --build
```
## Environment Variables
### Required Gitea Variables
- `NEXT_PUBLIC_BASE_URL` - Base URL for the application
- `MY_EMAIL` - Email address for contact
- `MY_INFO_EMAIL` - Info email address
- `LOG_LEVEL` - Logging level (info/debug)
### Required Gitea Secrets
- `MY_PASSWORD` - Email password
- `MY_INFO_PASSWORD` - Info email password
- `ADMIN_BASIC_AUTH` - Admin basic auth credentials
- `N8N_SECRET_TOKEN` - Optional: n8n webhook secret
### Optional Variables
- `N8N_WEBHOOK_URL` - n8n webhook URL for automation
## Health Checks
Both environments have health check endpoints:
- Production: `http://localhost:3000/api/health`
- Dev: `http://localhost:3002/api/health`
## Monitoring
### Check Container Status
```bash
# Production
docker compose -f docker-compose.production.yml ps
# Dev
docker compose -f docker-compose.staging.yml ps
```
### View Logs
```bash
# Production
docker logs portfolio-app --tail=100 -f
# Dev
docker logs portfolio-app-staging --tail=100 -f
```
### Health Check
```bash
# Production
curl http://localhost:3000/api/health
# Dev
curl http://localhost:3002/api/health
```
## Troubleshooting
### Container Won't Start
1. Check logs: `docker logs <container-name>`
2. Verify environment variables are set
3. Check database/redis connectivity
4. Verify ports aren't already in use
### Deployment Fails
1. Check Gitea Actions logs
2. Verify all required secrets/variables are set
3. Check if old containers are blocking ports
4. Verify Docker image builds successfully
### Zero-Downtime Issues
- Old container might still be running - check with `docker ps`
- Health checks might be failing - check container logs
- Port conflicts - verify ports 3000 and 3002 are available
## Rollback
If a deployment fails or causes issues:
```bash
# Production rollback
docker compose -f docker-compose.production.yml down
docker tag portfolio-app:previous portfolio-app:latest
docker compose -f docker-compose.production.yml up -d
# Dev rollback
docker compose -f docker-compose.staging.yml down
docker tag portfolio-app:staging-previous portfolio-app:staging
docker compose -f docker-compose.staging.yml up -d
```
## Best Practices
1. **Always test on dev branch first** before pushing to production
2. **Monitor health checks** after deployment
3. **Keep old images** for quick rollback (last 3 versions)
4. **Use feature flags** for new features
5. **Document breaking changes** before deploying
6. **Run tests locally** before pushing
## Network Configuration
- **Production Network**: `portfolio_net` + `proxy` (external)
- **Dev Network**: `portfolio_staging_net`
- **Isolation**: Complete separation ensures no interference
## Database Management
### Production Database
- **Container**: `portfolio-postgres`
- **Port**: `5432` (internal only)
- **Database**: `portfolio_db`
- **User**: `portfolio_user`
### Dev Database
- **Container**: `portfolio-postgres-staging`
- **Port**: `5434` (external), `5432` (internal)
- **Database**: `portfolio_staging_db`
- **User**: `portfolio_user`
## Redis Configuration
### Production Redis
- **Container**: `portfolio-redis`
- **Port**: `6379` (internal only)
### Dev Redis
- **Container**: `portfolio-redis-staging`
- **Port**: `6381` (external), `6379` (internal)

239
DEV-SETUP.md Normal file
View File

@@ -0,0 +1,239 @@
# 🚀 Development Environment Setup
This document explains how to set up and use the development environment for the portfolio project.
## ✨ Features
- **Automatic Database Setup**: PostgreSQL and Redis start automatically
- **Hot Reload**: Next.js development server with hot reload
- **Database Integration**: Real database integration for email management
- **Modern Admin Dashboard**: Completely redesigned admin interface
- **Minimal Setup**: Only essential services for fast development
## 🛠️ Quick Start
### Prerequisites
- Node.js 18+
- Docker & Docker Compose
- npm or yarn
### 1. Install Dependencies
```bash
npm install
```
### 2. Start Development Environment
#### Option A: Full Development Environment (with Docker)
```bash
npm run dev
```
This single command will:
- Start PostgreSQL database
- Start Redis cache
- Start Next.js development server
- Set up all environment variables
#### Option B: Simple Development Mode (without Docker)
```bash
npm run dev:simple
```
This starts only the Next.js development server without Docker services. Use this if you don't have Docker installed or want a faster startup.
### 3. Access Services
- **Portfolio**: http://localhost:3000
- **Admin Dashboard**: http://localhost:3000/manage
- **PostgreSQL**: localhost:5432
- **Redis**: localhost:6379
## 📧 Email Testing
The development environment supports email functionality:
1. Send emails through the contact form or admin panel
2. Emails are sent directly (configure SMTP in production)
3. Check console logs for email debugging
## 🗄️ Database
### Development Database
- **Host**: localhost:5432
- **Database**: portfolio_dev
- **User**: portfolio_user
- **Password**: portfolio_dev_pass
### Database Commands
```bash
# Generate Prisma client
npm run db:generate
# Push schema changes
npm run db:push
# Seed database with sample data
npm run db:seed
# Open Prisma Studio
npm run db:studio
# Reset database
npm run db:reset
```
## 🎨 Admin Dashboard
The new admin dashboard includes:
- **Overview**: Statistics and recent activity
- **Projects**: Manage portfolio projects
- **Emails**: Handle contact form submissions with beautiful templates
- **Analytics**: View performance metrics
- **Settings**: Import/export functionality
### Email Templates
Three beautiful email templates are available:
1. **Welcome Template** (Green): Friendly greeting with portfolio links
2. **Project Template** (Purple): Professional project discussion response
3. **Quick Template** (Orange): Fast acknowledgment response
## 🔧 Environment Variables
Create a `.env.local` file:
```env
# Development Database
DATABASE_URL="postgresql://portfolio_user:portfolio_dev_pass@localhost:5432/portfolio_dev?schema=public"
# Redis
REDIS_URL="redis://localhost:6379"
# Email (for production)
MY_EMAIL=contact@dk0.dev
MY_PASSWORD=your-email-password
# Application
NEXT_PUBLIC_BASE_URL=http://localhost:3000
NODE_ENV=development
```
## 🛑 Stopping the Environment
Use Ctrl+C to stop all services, or:
```bash
# Stop Docker services only
npm run docker:dev:down
```
## 🐳 Docker Commands
```bash
# Start only database services
npm run docker:dev
# Stop database services
npm run docker:dev:down
# View logs
docker compose -f docker-compose.dev.minimal.yml logs -f
```
## 📁 Project Structure
```
├── docker-compose.dev.minimal.yml # Minimal development services
├── scripts/
│ ├── dev-minimal.js # Main development script
│ ├── dev-simple.js # Simple development script
│ ├── setup-database.js # Database setup script
│ └── init-db.sql # Database initialization
├── app/
│ ├── admin/ # Admin dashboard
│ ├── api/
│ │ ├── contacts/ # Contact management API
│ │ └── email/ # Email sending API
│ └── components/
│ ├── ModernAdminDashboard.tsx
│ ├── EmailManager.tsx
│ └── EmailResponder.tsx
└── prisma/
└── schema.prisma # Database schema
```
## 🚨 Troubleshooting
### Docker Compose Not Found
If you get the error `spawn docker compose ENOENT`:
```bash
# Try the simple dev mode instead
npm run dev:simple
# Or install Docker Desktop
# Download from: https://www.docker.com/products/docker-desktop
```
### Port Conflicts
If ports are already in use:
```bash
# Check what's using the ports
lsof -i :3000
lsof -i :5432
lsof -i :6379
# Kill processes if needed
kill -9 <PID>
```
### Database Connection Issues
```bash
# Restart database services
npm run docker:dev:down
npm run docker:dev
# Check database status
docker compose -f docker-compose.dev.minimal.yml ps
```
### Email Not Working
1. Verify environment variables
2. Check browser console for errors
3. Ensure SMTP is configured for production
## 🎯 Production Deployment
For production deployment, use:
```bash
npm run build
npm run start
```
The production environment uses the production Docker Compose configuration.
## 📝 Notes
- The development environment automatically creates sample data
- Database changes are persisted in Docker volumes
- Hot reload works for all components and API routes
- Minimal setup for fast development startup
## 🔗 Links
- **Portfolio**: https://dk0.dev
- **Admin**: https://dk0.dev/manage
- **GitHub**: https://github.com/denniskonkol/portfolio

View File

@@ -82,12 +82,6 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# Copy Prisma files # Copy Prisma files
COPY --from=builder /app/prisma ./prisma COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=builder /app/node_modules/prisma ./node_modules/prisma
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
# Create scripts directory and copy start script AFTER standalone to ensure it's not overwritten
RUN mkdir -p scripts && chown nextjs:nodejs scripts
COPY --from=builder --chown=nextjs:nodejs /app/scripts/start-with-migrate.js ./scripts/start-with-migrate.js
# Note: Environment variables should be passed via docker-compose or runtime environment # Note: Environment variables should be passed via docker-compose or runtime environment
# DO NOT copy .env files into the image for security reasons # DO NOT copy .env files into the image for security reasons
@@ -103,4 +97,4 @@ ENV HOSTNAME="0.0.0.0"
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:3000/api/health || exit 1 CMD curl -f http://localhost:3000/api/health || exit 1
CMD ["node", "scripts/start-with-migrate.js"] CMD ["node", "server.js"]

185
GITEA_VARIABLES_SETUP.md Normal file
View File

@@ -0,0 +1,185 @@
# 🔧 Gitea Variables & Secrets Setup Guide
## Übersicht
In Gitea kannst du **Variables** (öffentlich) und **Secrets** (verschlüsselt) für dein Repository setzen. Diese werden in den CI/CD Workflows verwendet.
## 📍 Wo findest du die Einstellungen?
1. Gehe zu deinem Repository auf Gitea
2. Klicke auf **Settings** (Einstellungen)
3. Klicke auf **Variables** oder **Secrets** im linken Menü
## 🔑 Variablen für Production Branch
Für den `production` Branch brauchst du:
### Variables (öffentlich sichtbar):
- `NEXT_PUBLIC_BASE_URL` = `https://dk0.dev`
- `MY_EMAIL` = `contact@dk0.dev` (oder deine Email)
- `MY_INFO_EMAIL` = `info@dk0.dev` (oder deine Info-Email)
- `LOG_LEVEL` = `info`
- `N8N_WEBHOOK_URL` = `https://n8n.dk0.dev` (optional)
### Secrets (verschlüsselt):
- `MY_PASSWORD` = Dein Email-Passwort
- `MY_INFO_PASSWORD` = Dein Info-Email-Passwort
- `ADMIN_BASIC_AUTH` = `admin:dein_sicheres_passwort`
- `N8N_SECRET_TOKEN` = Dein n8n Secret Token (optional)
## 🧪 Variablen für Dev Branch
Für den `dev` Branch brauchst du die **gleichen** Variablen, aber mit anderen Werten:
### Variables:
- `NEXT_PUBLIC_BASE_URL` = `https://dev.dk0.dev` ⚠️ **WICHTIG: Andere URL!**
- `MY_EMAIL` = `contact@dk0.dev` (kann gleich sein)
- `MY_INFO_EMAIL` = `info@dk0.dev` (kann gleich sein)
- `LOG_LEVEL` = `debug` (für Dev mehr Logging)
- `N8N_WEBHOOK_URL` = `https://n8n.dk0.dev` (optional)
### Secrets:
- `MY_PASSWORD` = Dein Email-Passwort (kann gleich sein)
- `MY_INFO_PASSWORD` = Dein Info-Email-Passwort (kann gleich sein)
- `ADMIN_BASIC_AUTH` = `admin:staging_password` (kann anders sein)
- `N8N_SECRET_TOKEN` = Dein n8n Secret Token (optional)
## ✅ Lösung: Automatische Branch-Erkennung
**Gitea unterstützt keine branch-spezifischen Variablen, aber die Workflows erkennen automatisch den Branch!**
### Wie es funktioniert:
Die Workflows triggern auf unterschiedlichen Branches und verwenden automatisch die richtigen Defaults:
**Production Workflow** (`.gitea/workflows/production-deploy.yml`):
- Triggert nur auf `production` Branch
- Verwendet: `NEXT_PUBLIC_BASE_URL` (wenn gesetzt) oder Default: `https://dk0.dev`
**Dev Workflow** (`.gitea/workflows/dev-deploy.yml`):
- Triggert nur auf `dev` Branch
- Verwendet: `NEXT_PUBLIC_BASE_URL` (wenn gesetzt) oder Default: `https://dev.dk0.dev`
**Das bedeutet:**
- Du setzt **eine** Variable `NEXT_PUBLIC_BASE_URL` in Gitea
- **Production Branch** → verwendet diese Variable (oder Default `https://dk0.dev`)
- **Dev Branch** → verwendet diese Variable (oder Default `https://dev.dk0.dev`)
### ⚠️ WICHTIG:
Da beide Workflows die **gleiche Variable** verwenden, aber unterschiedliche Defaults haben:
**Option 1: Variable NICHT setzen (Empfohlen)**
- Production verwendet automatisch: `https://dk0.dev`
- Dev verwendet automatisch: `https://dev.dk0.dev`
- ✅ Funktioniert perfekt ohne Konfiguration!
**Option 2: Variable setzen**
- Wenn du `NEXT_PUBLIC_BASE_URL` = `https://dk0.dev` setzt
- Dann verwendet **beide** Branches diese URL (nicht ideal für Dev)
- ⚠️ Nicht empfohlen, da Dev dann die Production-URL verwendet
## ✅ Empfohlene Konfiguration
### ⭐ Einfachste Lösung: NICHTS setzen!
Die Workflows haben bereits die richtigen Defaults:
- **Production Branch** → automatisch `https://dk0.dev`
- **Dev Branch** → automatisch `https://dev.dk0.dev`
Du musst **NICHTS** in Gitea setzen, es funktioniert automatisch!
### Wenn du Variablen setzen willst:
**Nur diese Variablen setzen (für beide Branches):**
- `MY_EMAIL` = `contact@dk0.dev`
- `MY_INFO_EMAIL` = `info@dk0.dev`
- `LOG_LEVEL` = `info` (wird für Production verwendet, Dev überschreibt mit `debug`)
**Secrets (für beide Branches):**
- `MY_PASSWORD` = Dein Email-Passwort
- `MY_INFO_PASSWORD` = Dein Info-Email-Passwort
- `ADMIN_BASIC_AUTH` = `admin:dein_passwort`
- `N8N_SECRET_TOKEN` = Dein n8n Token (optional)
**⚠️ NICHT setzen:**
- `NEXT_PUBLIC_BASE_URL` - Lass diese Variable leer, damit jeder Branch seinen eigenen Default verwendet!
## 📝 Schritt-für-Schritt Anleitung
### 1. Gehe zu Repository Settings
```
https://git.dk0.dev/denshooter/portfolio/settings
```
### 2. Klicke auf "Variables" oder "Secrets"
### 3. Für Variables (öffentlich):
- Klicke auf **"New Variable"**
- **Name:** `NEXT_PUBLIC_BASE_URL`
- **Value:** `https://dk0.dev` (für Production)
- **Protect:** ✅ (optional, schützt vor Änderungen)
- Klicke **"Add Variable"**
### 4. Für Secrets (verschlüsselt):
- Klicke auf **"New Secret"**
- **Name:** `MY_PASSWORD`
- **Value:** Dein Passwort
- Klicke **"Add Secret"**
## 🔄 Aktuelle Workflow-Logik
Die Workflows verwenden diese einfache Logik:
```yaml
# Production Workflow (triggert nur auf production branch)
NEXT_PUBLIC_BASE_URL: ${{ vars.NEXT_PUBLIC_BASE_URL || 'https://dk0.dev' }}
# Dev Workflow (triggert nur auf dev branch)
NEXT_PUBLIC_BASE_URL: ${{ vars.NEXT_PUBLIC_BASE_URL || 'https://dev.dk0.dev' }}
```
**Das bedeutet:**
- Jeder Workflow hat seinen **eigenen Default**
- Wenn `NEXT_PUBLIC_BASE_URL` in Gitea gesetzt ist, wird diese verwendet
- Wenn **nicht** gesetzt, verwendet jeder Branch seinen eigenen Default
**⭐ Beste Lösung:**
- **NICHT** `NEXT_PUBLIC_BASE_URL` in Gitea setzen
- Dann verwendet Production automatisch `https://dk0.dev`
- Und Dev verwendet automatisch `https://dev.dk0.dev`
- ✅ Perfekt getrennt, ohne Konfiguration!
## 🎯 Best Practice
1. **Production:** Setze alle Variablen explizit in Gitea
2. **Dev:** Nutze die Defaults im Workflow (oder setze separate Variablen)
3. **Secrets:** Immer in Gitea Secrets setzen, nie in Code!
## 🔍 Prüfen ob Variablen gesetzt sind
In den Workflow-Logs siehst du:
```
📝 Using Gitea Variables and Secrets:
- NEXT_PUBLIC_BASE_URL: https://dk0.dev
```
Wenn eine Variable fehlt, wird der Default verwendet.
## ⚙️ Alternative: Environment-spezifische Variablen
Falls du separate Variablen für Dev und Production willst, können wir die Workflows anpassen:
```yaml
# Production
NEXT_PUBLIC_BASE_URL: ${{ vars.NEXT_PUBLIC_BASE_URL_PRODUCTION || 'https://dk0.dev' }}
# Dev
NEXT_PUBLIC_BASE_URL: ${{ vars.NEXT_PUBLIC_BASE_URL_DEV || 'https://dev.dk0.dev' }}
```
Dann könntest du setzen:
- `NEXT_PUBLIC_BASE_URL_PRODUCTION` = `https://dk0.dev`
- `NEXT_PUBLIC_BASE_URL_DEV` = `https://dev.dk0.dev`
Soll ich die Workflows entsprechend anpassen?

View File

@@ -0,0 +1,198 @@
# 🔧 Nginx Proxy Manager Setup Guide
## Übersicht
Dieses Projekt nutzt **Nginx Proxy Manager** als Reverse Proxy. Die Container sind im `proxy` Netzwerk, damit Nginx Proxy Manager auf sie zugreifen kann.
## 🐳 Docker Netzwerk-Konfiguration
Die Container sind bereits im `proxy` Netzwerk konfiguriert:
**Production:**
```yaml
networks:
- portfolio_net
- proxy # ✅ Bereits konfiguriert
```
**Staging:**
```yaml
networks:
- portfolio_staging_net
- proxy # ✅ Bereits konfiguriert
```
## 📋 Nginx Proxy Manager Konfiguration
### Production (dk0.dev)
1. **Gehe zu Nginx Proxy Manager** → Hosts → Proxy Hosts → Add Proxy Host
2. **Details Tab:**
- **Domain Names:** `dk0.dev`, `www.dk0.dev`
- **Scheme:** `http`
- **Forward Hostname/IP:** `portfolio-app` (Container-Name)
- **Forward Port:** `3000`
- **Cache Assets:** ✅ (optional)
- **Block Common Exploits:** ✅
- **Websockets Support:** ✅ (für Chat/Activity)
3. **SSL Tab:**
- **SSL Certificate:** Request a new SSL Certificate
- **Force SSL:** ✅
- **HTTP/2 Support:** ✅
- **HSTS Enabled:** ✅
4. **Advanced Tab:**
```
# Custom Nginx Configuration
# Fix for 421 Misdirected Request
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
# Fix HTTP/2 connection reuse issues
proxy_http_version 1.1;
proxy_set_header Connection "";
# Timeouts
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
```
### Staging (dev.dk0.dev)
1. **Gehe zu Nginx Proxy Manager** → Hosts → Proxy Hosts → Add Proxy Host
2. **Details Tab:**
- **Domain Names:** `dev.dk0.dev`
- **Scheme:** `http`
- **Forward Hostname/IP:** `portfolio-app-staging` (Container-Name)
- **Forward Port:** `3000` (interner Port im Container)
- **Cache Assets:** ❌ (für Dev besser deaktiviert)
- **Block Common Exploits:** ✅
- **Websockets Support:** ✅
3. **SSL Tab:**
- **SSL Certificate:** Request a new SSL Certificate
- **Force SSL:** ✅
- **HTTP/2 Support:** ✅
- **HSTS Enabled:** ✅
4. **Advanced Tab:**
```
# Custom Nginx Configuration
# Fix for 421 Misdirected Request
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
# Fix HTTP/2 connection reuse issues
proxy_http_version 1.1;
proxy_set_header Connection "";
# Timeouts
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
```
## 🔍 421 Misdirected Request - Lösung
Der **421 Misdirected Request** Fehler tritt auf, wenn:
1. **HTTP/2 Connection Reuse:** Nginx Proxy Manager versucht, eine HTTP/2-Verbindung wiederzuverwenden, aber der Host-Header stimmt nicht überein
2. **Host-Header nicht richtig weitergegeben:** Der Container erhält den falschen Host-Header
### Lösung 1: Advanced Tab Konfiguration (Wichtig!)
Füge diese Zeilen im **Advanced Tab** von Nginx Proxy Manager hinzu:
```nginx
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
```
### Lösung 2: Container-Namen verwenden
Stelle sicher, dass du den **Container-Namen** (nicht IP) verwendest:
- Production: `portfolio-app`
- Staging: `portfolio-app-staging`
### Lösung 3: Netzwerk prüfen
Stelle sicher, dass beide Container im `proxy` Netzwerk sind:
```bash
# Prüfen
docker network inspect proxy
# Sollte enthalten:
# - portfolio-app
# - portfolio-app-staging
```
## ✅ Checkliste
- [ ] Container sind im `proxy` Netzwerk
- [ ] Nginx Proxy Manager nutzt Container-Namen (nicht IP)
- [ ] Advanced Tab Konfiguration ist gesetzt
- [ ] `proxy_http_version 1.1` ist gesetzt
- [ ] `proxy_set_header Host $host` ist gesetzt
- [ ] SSL-Zertifikat ist konfiguriert
- [ ] Websockets Support ist aktiviert
## 🐛 Troubleshooting
### 421 Fehler weiterhin vorhanden?
1. **Prüfe Container-Namen:**
```bash
docker ps --format "table {{.Names}}\t{{.Status}}"
```
2. **Prüfe Netzwerk:**
```bash
docker network inspect proxy | grep -A 5 portfolio
```
3. **Prüfe Nginx Proxy Manager Logs:**
- Gehe zu Nginx Proxy Manager → System Logs
- Suche nach "421" oder "misdirected"
4. **Teste direkt:**
```bash
# Vom Host aus
curl -H "Host: dk0.dev" http://portfolio-app:3000
# Sollte funktionieren
```
5. **Deaktiviere HTTP/2 temporär:**
- In Nginx Proxy Manager → SSL Tab
- **HTTP/2 Support:** ❌
- Teste ob es funktioniert
## 📝 Wichtige Hinweise
- **Container-Namen sind wichtig:** Nutze `portfolio-app` nicht `localhost` oder IP
- **Port:** Immer Port `3000` (interner Container-Port), nicht `3000:3000`
- **Netzwerk:** Beide Container müssen im `proxy` Netzwerk sein
- **HTTP/2:** Kann Probleme verursachen, wenn Advanced Config fehlt
## 🔄 Nach Deployment
Nach jedem Deployment:
1. Prüfe ob Container läuft: `docker ps | grep portfolio`
2. Prüfe ob Container im proxy-Netzwerk ist
3. Teste die URL im Browser
4. Prüfe Nginx Proxy Manager Logs bei Problemen

View File

@@ -1,7 +1,3 @@
# Quick links
- **Ops / setup / deployment / testing**: `docs/OPERATIONS.md`
# Dennis Konkol Portfolio - Modern Dark Theme # Dennis Konkol Portfolio - Modern Dark Theme
Ein modernes, responsives Portfolio mit dunklem Design, coolen Animationen und einem integrierten Admin-Dashboard. Ein modernes, responsives Portfolio mit dunklem Design, coolen Animationen und einem integrierten Admin-Dashboard.
@@ -52,10 +48,8 @@ npm run start # Production Server
## 📖 Dokumentation ## 📖 Dokumentation
- [Development Setup](DEV-SETUP.md) - Detaillierte Setup-Anleitung - [Development Setup](DEV-SETUP.md) - Detaillierte Setup-Anleitung
- [Deployment Setup](DEPLOYMENT_SETUP.md) - Production Deployment - [Deployment Guide](DEPLOYMENT.md) - Production Deployment
- [Analytics](ANALYTICS.md) - Analytics und Performance - [Analytics](ANALYTICS.md) - Analytics und Performance
- [CMS Guide](docs/CMS_GUIDE.md) - Inhalte/Sprachen pflegen (Rich Text)
- [Testing & Deployment](docs/TESTING_AND_DEPLOYMENT.md) - Branches → Container → Domains
## 🔗 Links ## 🔗 Links

284
TESTING_GUIDE.md Normal file
View File

@@ -0,0 +1,284 @@
# 🧪 Automated Testing Guide
This guide explains how to run automated tests for critical paths, hydration, emails, and more.
## 📋 Test Types
### 1. Unit Tests (Jest)
Tests individual components and functions in isolation.
```bash
npm run test # Run all unit tests
npm run test:watch # Watch mode
npm run test:coverage # With coverage report
```
### 2. E2E Tests (Playwright)
Tests complete user flows in a real browser.
```bash
npm run test:e2e # Run all E2E tests
npm run test:e2e:ui # Run with UI mode (visual)
npm run test:e2e:headed # Run with visible browser
npm run test:e2e:debug # Debug mode
```
### 3. Critical Path Tests
Tests the most important user flows.
```bash
npm run test:critical # Run critical path tests only
```
### 4. Hydration Tests
Ensures React hydration works without errors.
```bash
npm run test:hydration # Run hydration tests only
```
### 5. Email Tests
Tests email API endpoints.
```bash
npm run test:email # Run email tests only
```
### 6. Performance Tests
Checks page load times and performance.
```bash
npm run test:performance # Run performance tests
```
### 7. Accessibility Tests
Basic accessibility checks.
```bash
npm run test:accessibility # Run accessibility tests
```
## 🚀 Running All Tests
### Quick Test (Recommended)
```bash
npm run test:all
```
This runs:
- ✅ TypeScript check
- ✅ ESLint
- ✅ Build
- ✅ Unit tests
- ✅ Critical paths
- ✅ Hydration tests
- ✅ Email tests
- ✅ Performance tests
- ✅ Accessibility tests
### Individual Test Suites
```bash
# Unit tests only
npm run test
# E2E tests only
npm run test:e2e
# Both
npm run test && npm run test:e2e
```
## 📝 What Gets Tested
### Critical Paths
- ✅ Home page loads correctly
- ✅ Projects page displays projects
- ✅ Individual project pages work
- ✅ Admin dashboard is accessible
- ✅ API health endpoint
- ✅ API projects endpoint
### Hydration
- ✅ No hydration errors in console
- ✅ No duplicate React key warnings
- ✅ Client-side navigation works
- ✅ Server and client HTML match
- ✅ Interactive elements work after hydration
### Email
- ✅ Email API accepts requests
- ✅ Required field validation
- ✅ Email format validation
- ✅ Rate limiting (if implemented)
- ✅ Email respond endpoint
### Performance
- ✅ Page load times (< 5s)
- No large layout shifts
- Images are optimized
- API response times (< 1s)
### Accessibility
- Proper heading structure
- Images have alt text
- Links have descriptive text
- Forms have labels
## 🎯 Pre-Push Testing
Before pushing to main, run:
```bash
# Full test suite
npm run test:all
# Or manually:
npm run build
npm run lint
npx tsc --noEmit
npm run test
npm run test:critical
npm run test:hydration
```
## 🔧 Configuration
### Playwright Config
Located in `playwright.config.ts`
- **Base URL**: `http://localhost:3000` (or set `PLAYWRIGHT_TEST_BASE_URL`)
- **Browsers**: Chromium, Firefox, WebKit, Mobile Chrome, Mobile Safari
- **Retries**: 2 retries in CI, 0 locally
- **Screenshots**: On failure
- **Videos**: On failure
### Jest Config
Located in `jest.config.ts`
- **Environment**: jsdom
- **Coverage**: v8 provider
- **Setup**: `jest.setup.ts`
## 🐛 Debugging Tests
### Playwright Debug Mode
```bash
npm run test:e2e:debug
```
This opens Playwright Inspector where you can:
- Step through tests
- Inspect elements
- View console logs
- See network requests
### UI Mode (Visual)
```bash
npm run test:e2e:ui
```
Shows a visual interface to:
- See all tests
- Run specific tests
- Watch tests execute
- View results
### Headed Mode
```bash
npm run test:e2e:headed
```
Runs tests with visible browser (useful for debugging).
## 📊 Test Reports
### Playwright HTML Report
After running E2E tests:
```bash
npx playwright show-report
```
Shows:
- Test results
- Screenshots on failure
- Videos on failure
- Timeline of test execution
### Jest Coverage Report
```bash
npm run test:coverage
```
Generates coverage report in `coverage/` directory.
## 🚨 Common Issues
### Tests Fail Locally But Pass in CI
- Check environment variables
- Ensure database is set up
- Check for port conflicts
### Hydration Errors
- Check for server/client mismatches
- Ensure no conditional rendering based on `window`
- Check for date/time differences
### Email Tests Fail
- Email service might not be configured
- Check environment variables
- Tests are designed to handle missing email service
### Performance Tests Fail
- Network might be slow
- Adjust thresholds in test file
- Check for heavy resources loading
## 📝 Writing New Tests
### E2E Test Example
```typescript
import { test, expect } from '@playwright/test';
test('My new feature works', async ({ page }) => {
await page.goto('/my-page');
await expect(page.locator('h1')).toContainText('Expected Text');
});
```
### Unit Test Example
```typescript
import { render, screen } from '@testing-library/react';
import MyComponent from './MyComponent';
test('renders correctly', () => {
render(<MyComponent />);
expect(screen.getByText('Hello')).toBeInTheDocument();
});
```
## 🎯 CI/CD Integration
### GitHub Actions Example
```yaml
- name: Run tests
run: |
npm install
npm run test:all
```
### Pre-Push Hook
Add to `.git/hooks/pre-push`:
```bash
#!/bin/bash
npm run test:all
```
## 📚 Resources
- [Playwright Docs](https://playwright.dev)
- [Jest Docs](https://jestjs.io)
- [Testing Library](https://testing-library.com)
---
**Remember**: Tests should be fast, reliable, and easy to understand! 🚀

View File

@@ -1,27 +0,0 @@
import { NextIntlClientProvider } from "next-intl";
import { setRequestLocale } from "next-intl/server";
import React from "react";
import ConsentBanner from "../components/ConsentBanner";
export default async function LocaleLayout({
children,
params,
}: {
children: React.ReactNode;
params: Promise<{ locale: string }>;
}) {
const { locale } = await params;
// Ensure next-intl actually uses the route segment locale for this request.
setRequestLocale(locale);
// Load messages explicitly by route locale to avoid falling back to the wrong
// language when request-level locale detection is unavailable/misconfigured.
const messages = (await import(`../../messages/${locale}.json`)).default;
return (
<NextIntlClientProvider locale={locale} messages={messages}>
{children}
<ConsentBanner />
</NextIntlClientProvider>
);
}

View File

@@ -1,19 +0,0 @@
import type { Metadata } from "next";
import { getLanguageAlternates, toAbsoluteUrl } from "@/lib/seo";
export { default } from "../../legal-notice/page";
export async function generateMetadata({
params,
}: {
params: Promise<{ locale: string }>;
}): Promise<Metadata> {
const { locale } = await params;
const languages = getLanguageAlternates({ pathWithoutLocale: "legal-notice" });
return {
alternates: {
canonical: toAbsoluteUrl(`/${locale}/legal-notice`),
languages,
},
};
}

View File

@@ -1,23 +0,0 @@
import type { Metadata } from "next";
import HomePage from "../_ui/HomePage";
import { getLanguageAlternates, toAbsoluteUrl } from "@/lib/seo";
export async function generateMetadata({
params,
}: {
params: Promise<{ locale: string }>;
}): Promise<Metadata> {
const { locale } = await params;
const languages = getLanguageAlternates({ pathWithoutLocale: "" });
return {
alternates: {
canonical: toAbsoluteUrl(`/${locale}`),
languages,
},
};
}
export default function Page() {
return <HomePage />;
}

View File

@@ -1,19 +0,0 @@
import type { Metadata } from "next";
import { getLanguageAlternates, toAbsoluteUrl } from "@/lib/seo";
export { default } from "../../privacy-policy/page";
export async function generateMetadata({
params,
}: {
params: Promise<{ locale: string }>;
}): Promise<Metadata> {
const { locale } = await params;
const languages = getLanguageAlternates({ pathWithoutLocale: "privacy-policy" });
return {
alternates: {
canonical: toAbsoluteUrl(`/${locale}/privacy-policy`),
languages,
},
};
}

View File

@@ -1,53 +0,0 @@
import { prisma } from "@/lib/prisma";
import ProjectDetailClient from "@/app/_ui/ProjectDetailClient";
import { notFound } from "next/navigation";
import type { Metadata } from "next";
import { getLanguageAlternates, toAbsoluteUrl } from "@/lib/seo";
export const revalidate = 300;
export async function generateMetadata({
params,
}: {
params: Promise<{ locale: string; slug: string }>;
}): Promise<Metadata> {
const { locale, slug } = await params;
const languages = getLanguageAlternates({ pathWithoutLocale: `projects/${slug}` });
return {
alternates: {
canonical: toAbsoluteUrl(`/${locale}/projects/${slug}`),
languages,
},
};
}
export default async function ProjectPage({
params,
}: {
params: Promise<{ locale: string; slug: string }>;
}) {
const { locale, slug } = await params;
const project = await prisma.project.findFirst({
where: { slug, published: true },
include: {
translations: {
where: { locale },
select: { title: true, description: true },
},
},
});
if (!project) return notFound();
const tr = project.translations?.[0];
const { translations: _translations, ...rest } = project;
const localized = {
...rest,
title: tr?.title ?? project.title,
description: tr?.description ?? project.description,
};
return <ProjectDetailClient project={localized} locale={locale} />;
}

View File

@@ -1,53 +0,0 @@
import { prisma } from "@/lib/prisma";
import ProjectsPageClient from "@/app/_ui/ProjectsPageClient";
import type { Metadata } from "next";
import { getLanguageAlternates, toAbsoluteUrl } from "@/lib/seo";
export const revalidate = 300;
export async function generateMetadata({
params,
}: {
params: Promise<{ locale: string }>;
}): Promise<Metadata> {
const { locale } = await params;
const languages = getLanguageAlternates({ pathWithoutLocale: "projects" });
return {
alternates: {
canonical: toAbsoluteUrl(`/${locale}/projects`),
languages,
},
};
}
export default async function ProjectsPage({
params,
}: {
params: Promise<{ locale: string }>;
}) {
const { locale } = await params;
const projects = await prisma.project.findMany({
where: { published: true },
orderBy: { createdAt: "desc" },
include: {
translations: {
where: { locale },
select: { title: true, description: true },
},
},
});
const localized = projects.map((p) => {
const tr = p.translations?.[0];
const { translations: _translations, ...rest } = p;
return {
...rest,
title: tr?.title ?? p.title,
description: tr?.description ?? p.description,
};
});
return <ProjectsPageClient projects={localized} locale={locale} />;
}

View File

@@ -1,27 +1,43 @@
import { GET } from '@/app/api/fetchAllProjects/route';
import { NextResponse } from 'next/server'; import { NextResponse } from 'next/server';
jest.mock('@/lib/prisma', () => ({ // Wir mocken node-fetch direkt
prisma: { jest.mock('node-fetch', () => ({
project: { __esModule: true,
findMany: jest.fn(async () => [ default: jest.fn(() =>
{ Promise.resolve({
id: 1, json: () =>
slug: 'just-doing-some-testing', Promise.resolve({
title: 'Just Doing Some Testing', posts: [
updatedAt: new Date('2025-02-13T14:25:38.000Z'), {
metaDescription: 'Hello bla bla bla bla', id: '67ac8dfa709c60000117d312',
}, title: 'Just Doing Some Testing',
{ meta_description: 'Hello bla bla bla bla',
id: 2, slug: 'just-doing-some-testing',
slug: 'blockchain-based-voting-system', updated_at: '2025-02-13T14:25:38.000+00:00',
title: 'Blockchain Based Voting System', },
updatedAt: new Date('2025-02-13T16:54:42.000Z'), {
metaDescription: id: '67aaffc3709c60000117d2d9',
'This project aims to revolutionize voting systems by leveraging blockchain to ensure security, transparency, and immutability.', title: 'Blockchain Based Voting System',
}, meta_description:
]), 'This project aims to revolutionize voting systems by leveraging blockchain to ensure security, transparency, and immutability.',
}, slug: 'blockchain-based-voting-system',
}, updated_at: '2025-02-13T16:54:42.000+00:00',
},
],
meta: {
pagination: {
limit: 'all',
next: null,
page: 1,
pages: 1,
prev: null,
total: 2,
},
},
}),
})
),
})); }));
jest.mock('next/server', () => ({ jest.mock('next/server', () => ({
@@ -31,8 +47,12 @@ jest.mock('next/server', () => ({
})); }));
describe('GET /api/fetchAllProjects', () => { describe('GET /api/fetchAllProjects', () => {
beforeAll(() => {
process.env.GHOST_API_URL = 'http://localhost:2368';
process.env.GHOST_API_KEY = 'some-key';
});
it('should return a list of projects (partial match)', async () => { it('should return a list of projects (partial match)', async () => {
const { GET } = await import('@/app/api/fetchAllProjects/route');
await GET(); await GET();
// Den tatsächlichen Argumentwert extrahieren // Den tatsächlichen Argumentwert extrahieren
@@ -41,11 +61,11 @@ describe('GET /api/fetchAllProjects', () => {
expect(responseArg).toMatchObject({ expect(responseArg).toMatchObject({
posts: expect.arrayContaining([ posts: expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: '1', id: '67ac8dfa709c60000117d312',
title: 'Just Doing Some Testing', title: 'Just Doing Some Testing',
}), }),
expect.objectContaining({ expect.objectContaining({
id: '2', id: '67aaffc3709c60000117d2d9',
title: 'Blockchain Based Voting System', title: 'Blockchain Based Voting System',
}), }),
]), ]),

View File

@@ -1,23 +1,26 @@
import { GET } from '@/app/api/fetchProject/route';
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
jest.mock('@/lib/prisma', () => ({ // Mock node-fetch so the route uses it as a reliable fallback
prisma: { jest.mock('node-fetch', () => ({
project: { __esModule: true,
findUnique: jest.fn(async ({ where }: { where: { slug: string } }) => { default: jest.fn(() =>
if (where.slug !== 'blockchain-based-voting-system') return null; Promise.resolve({
return { ok: true,
id: 2, json: () =>
title: 'Blockchain Based Voting System', Promise.resolve({
metaDescription: posts: [
'This project aims to revolutionize voting systems by leveraging blockchain to ensure security, transparency, and immutability.', {
slug: 'blockchain-based-voting-system', id: '67aaffc3709c60000117d2d9',
updatedAt: new Date('2025-02-13T16:54:42.000Z'), title: 'Blockchain Based Voting System',
description: null, meta_description: 'This project aims to revolutionize voting systems by leveraging blockchain to ensure security, transparency, and immutability.',
content: null, slug: 'blockchain-based-voting-system',
}; updated_at: '2025-02-13T16:54:42.000+00:00',
}), },
}, ],
}, }),
})
),
})); }));
jest.mock('next/server', () => ({ jest.mock('next/server', () => ({
@@ -26,8 +29,12 @@ jest.mock('next/server', () => ({
}, },
})); }));
describe('GET /api/fetchProject', () => { describe('GET /api/fetchProject', () => {
beforeAll(() => {
process.env.GHOST_API_URL = 'http://localhost:2368';
process.env.GHOST_API_KEY = 'some-key';
});
it('should fetch a project by slug', async () => { it('should fetch a project by slug', async () => {
const { GET } = await import('@/app/api/fetchProject/route');
const mockRequest = { const mockRequest = {
url: 'http://localhost/api/fetchProject?slug=blockchain-based-voting-system', url: 'http://localhost/api/fetchProject?slug=blockchain-based-voting-system',
} as unknown as NextRequest; } as unknown as NextRequest;
@@ -37,11 +44,11 @@ describe('GET /api/fetchProject', () => {
expect(NextResponse.json).toHaveBeenCalledWith({ expect(NextResponse.json).toHaveBeenCalledWith({
posts: [ posts: [
{ {
id: '2', id: '67aaffc3709c60000117d2d9',
title: 'Blockchain Based Voting System', title: 'Blockchain Based Voting System',
meta_description: 'This project aims to revolutionize voting systems by leveraging blockchain to ensure security, transparency, and immutability.', meta_description: 'This project aims to revolutionize voting systems by leveraging blockchain to ensure security, transparency, and immutability.',
slug: 'blockchain-based-voting-system', slug: 'blockchain-based-voting-system',
updated_at: '2025-02-13T16:54:42.000Z', updated_at: '2025-02-13T16:54:42.000+00:00',
}, },
], ],
}); });

View File

@@ -34,38 +34,77 @@ jest.mock("next/server", () => {
}; };
}); });
jest.mock("@/lib/sitemap", () => ({ import { GET } from "@/app/api/sitemap/route";
getSitemapEntries: jest.fn(async () => [
{ // Mock node-fetch so we don't perform real network requests in tests
url: "https://dki.one/en", jest.mock("node-fetch", () => ({
lastModified: "2025-01-01T00:00:00.000Z", __esModule: true,
}, default: jest.fn(() =>
{ Promise.resolve({
url: "https://dki.one/de", ok: true,
lastModified: "2025-01-01T00:00:00.000Z", json: () =>
}, Promise.resolve({
{ posts: [
url: "https://dki.one/en/projects/blockchain-based-voting-system", {
lastModified: "2025-02-13T16:54:42.000Z", id: "67ac8dfa709c60000117d312",
}, title: "Just Doing Some Testing",
{ meta_description: "Hello bla bla bla bla",
url: "https://dki.one/de/projects/blockchain-based-voting-system", slug: "just-doing-some-testing",
lastModified: "2025-02-13T16:54:42.000Z", updated_at: "2025-02-13T14:25:38.000+00:00",
}, },
]), {
generateSitemapXml: jest.fn( id: "67aaffc3709c60000117d2d9",
() => title: "Blockchain Based Voting System",
'<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://dki.one/en</loc></url></urlset>', meta_description:
"This project aims to revolutionize voting systems by leveraging blockchain to ensure security, transparency, and immutability.",
slug: "blockchain-based-voting-system",
updated_at: "2025-02-13T16:54:42.000+00:00",
},
],
meta: {
pagination: {
limit: "all",
next: null,
page: 1,
pages: 1,
prev: null,
total: 2,
},
},
}),
}),
), ),
})); }));
describe("GET /api/sitemap", () => { describe("GET /api/sitemap", () => {
beforeAll(() => { beforeAll(() => {
process.env.GHOST_API_URL = "http://localhost:2368";
process.env.GHOST_API_KEY = "test-api-key";
process.env.NEXT_PUBLIC_BASE_URL = "https://dki.one"; process.env.NEXT_PUBLIC_BASE_URL = "https://dki.one";
// Provide mock posts via env so route can use them without fetching
process.env.GHOST_MOCK_POSTS = JSON.stringify({
posts: [
{
id: "67ac8dfa709c60000117d312",
title: "Just Doing Some Testing",
meta_description: "Hello bla bla bla bla",
slug: "just-doing-some-testing",
updated_at: "2025-02-13T14:25:38.000+00:00",
},
{
id: "67aaffc3709c60000117d2d9",
title: "Blockchain Based Voting System",
meta_description:
"This project aims to revolutionize voting systems by leveraging blockchain to ensure security, transparency, and immutability.",
slug: "blockchain-based-voting-system",
updated_at: "2025-02-13T16:54:42.000+00:00",
},
],
});
}); });
it("should return a sitemap", async () => { it("should return a sitemap", async () => {
const { GET } = await import("@/app/api/sitemap/route");
const response = await GET(); const response = await GET();
// Get the body text from the NextResponse // Get the body text from the NextResponse
@@ -74,7 +113,15 @@ describe("GET /api/sitemap", () => {
expect(body).toContain( expect(body).toContain(
'<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">', '<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">',
); );
expect(body).toContain("<loc>https://dki.one/en</loc>"); expect(body).toContain("<loc>https://dki.one/</loc>");
expect(body).toContain("<loc>https://dki.one/legal-notice</loc>");
expect(body).toContain("<loc>https://dki.one/privacy-policy</loc>");
expect(body).toContain(
"<loc>https://dki.one/projects/just-doing-some-testing</loc>",
);
expect(body).toContain(
"<loc>https://dki.one/projects/blockchain-based-voting-system</loc>",
);
// Note: Headers are not available in test environment // Note: Headers are not available in test environment
}); });
}); });

View File

@@ -21,7 +21,7 @@ describe('Header', () => {
it('renders the mobile header', () => { it('renders the mobile header', () => {
render(<Header />); render(<Header />);
// Check for mobile menu button (hamburger icon) // Check for mobile menu button (hamburger icon)
const menuButton = screen.getByLabelText('Open menu'); const menuButton = screen.getByRole('button');
expect(menuButton).toBeInTheDocument(); expect(menuButton).toBeInTheDocument();
}); });
}); });

View File

@@ -1,4 +1,5 @@
import "@testing-library/jest-dom"; import "@testing-library/jest-dom";
import { GET } from "@/app/sitemap.xml/route";
jest.mock("next/server", () => ({ jest.mock("next/server", () => ({
NextResponse: jest.fn().mockImplementation((body: unknown, init?: ResponseInit) => { NextResponse: jest.fn().mockImplementation((body: unknown, init?: ResponseInit) => {
@@ -10,32 +11,71 @@ jest.mock("next/server", () => ({
}), }),
})); }));
jest.mock("@/lib/sitemap", () => ({ // Sitemap XML used by node-fetch mock
getSitemapEntries: jest.fn(async () => [ const sitemapXml = `
{ <urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">
url: "https://dki.one/en", <url>
lastModified: "2025-01-01T00:00:00.000Z", <loc>https://dki.one/</loc>
}, </url>
]), <url>
generateSitemapXml: jest.fn( <loc>https://dki.one/legal-notice</loc>
() => </url>
'<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://dki.one/en</loc></url></urlset>', <url>
<loc>https://dki.one/privacy-policy</loc>
</url>
<url>
<loc>https://dki.one/projects/just-doing-some-testing</loc>
</url>
<url>
<loc>https://dki.one/projects/blockchain-based-voting-system</loc>
</url>
</urlset>
`;
// Mock node-fetch for sitemap endpoint (hoisted by Jest)
jest.mock("node-fetch", () => ({
__esModule: true,
default: jest.fn((_url: string) =>
Promise.resolve({ ok: true, text: () => Promise.resolve(sitemapXml) }),
), ),
})); }));
describe("Sitemap Component", () => { describe("Sitemap Component", () => {
beforeAll(() => { beforeAll(() => {
process.env.NEXT_PUBLIC_BASE_URL = "https://dki.one"; process.env.NEXT_PUBLIC_BASE_URL = "https://dki.one";
// Provide sitemap XML directly so route uses it without fetching
process.env.GHOST_MOCK_SITEMAP = sitemapXml;
// Mock global.fetch too, to avoid any network calls
global.fetch = jest.fn().mockImplementation((url: string) => {
if (url.includes("/api/sitemap")) {
return Promise.resolve({
ok: true,
text: () => Promise.resolve(sitemapXml),
});
}
return Promise.reject(new Error(`Unknown URL: ${url}`));
});
}); });
it("should render the sitemap XML", async () => { it("should render the sitemap XML", async () => {
const { GET } = await import("@/app/sitemap.xml/route");
const response = await GET(); const response = await GET();
expect(response.body).toContain( expect(response.body).toContain(
'<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">', '<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">',
); );
expect(response.body).toContain("<loc>https://dki.one/en</loc>"); expect(response.body).toContain("<loc>https://dki.one/</loc>");
expect(response.body).toContain("<loc>https://dki.one/legal-notice</loc>");
expect(response.body).toContain(
"<loc>https://dki.one/privacy-policy</loc>",
);
expect(response.body).toContain(
"<loc>https://dki.one/projects/just-doing-some-testing</loc>",
);
expect(response.body).toContain(
"<loc>https://dki.one/projects/blockchain-based-voting-system</loc>",
);
// Note: Headers are not available in test environment // Note: Headers are not available in test environment
}); });
}); });

View File

@@ -1,31 +0,0 @@
"use client";
import React, { useEffect, useState } from "react";
type ActivityFeedComponent = React.ComponentType<Record<string, never>>;
export default function ActivityFeedClient() {
const [Comp, setComp] = useState<ActivityFeedComponent | null>(null);
useEffect(() => {
let cancelled = false;
(async () => {
try {
const mod = await import("../components/ActivityFeed");
const C = (mod as unknown as { default?: ActivityFeedComponent }).default;
if (!cancelled && typeof C === "function") {
setComp(() => C);
}
} catch {
// ignore
}
})();
return () => {
cancelled = true;
};
}, []);
if (!Comp) return null;
return <Comp />;
}

View File

@@ -1,115 +0,0 @@
import Header from "../components/Header";
import Hero from "../components/Hero";
import About from "../components/About";
import Projects from "../components/Projects";
import Contact from "../components/Contact";
import Footer from "../components/Footer";
import Script from "next/script";
import ActivityFeedClient from "./ActivityFeedClient";
export default function HomePage() {
return (
<div className="min-h-screen">
<Script
id={"structured-data"}
type="application/ld+json"
dangerouslySetInnerHTML={{
__html: JSON.stringify({
"@context": "https://schema.org",
"@type": "Person",
name: "Dennis Konkol",
url: "https://dk0.dev",
jobTitle: "Software Engineer",
address: {
"@type": "PostalAddress",
addressLocality: "Osnabrück",
addressCountry: "Germany",
},
sameAs: [
"https://github.com/Denshooter",
"https://linkedin.com/in/dkonkol",
],
}),
}}
/>
<ActivityFeedClient />
<Header />
{/* Spacer to prevent navbar overlap */}
<div className="h-24 md:h-32" aria-hidden="true"></div>
<main className="relative">
<Hero />
{/* Wavy Separator 1 - Hero to About */}
<div className="relative h-24 overflow-hidden">
<svg
className="absolute inset-0 w-full h-full"
viewBox="0 0 1440 120"
preserveAspectRatio="none"
>
<path
d="M0,64 C240,96 480,32 720,64 C960,96 1200,32 1440,64 L1440,120 L0,120 Z"
fill="url(#gradient1)"
/>
<defs>
<linearGradient id="gradient1" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" stopColor="#BAE6FD" stopOpacity="0.4" />
<stop offset="50%" stopColor="#DDD6FE" stopOpacity="0.4" />
<stop offset="100%" stopColor="#FBCFE8" stopOpacity="0.4" />
</linearGradient>
</defs>
</svg>
</div>
<About />
{/* Wavy Separator 2 - About to Projects */}
<div className="relative h-24 overflow-hidden">
<svg
className="absolute inset-0 w-full h-full"
viewBox="0 0 1440 120"
preserveAspectRatio="none"
>
<path
d="M0,32 C240,64 480,96 720,32 C960,64 1200,96 1440,32 L1440,120 L0,120 Z"
fill="url(#gradient2)"
/>
<defs>
<linearGradient id="gradient2" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" stopColor="#FED7AA" stopOpacity="0.4" />
<stop offset="50%" stopColor="#FDE68A" stopOpacity="0.4" />
<stop offset="100%" stopColor="#FCA5A5" stopOpacity="0.4" />
</linearGradient>
</defs>
</svg>
</div>
<Projects />
{/* Wavy Separator 3 - Projects to Contact */}
<div className="relative h-24 overflow-hidden">
<svg
className="absolute inset-0 w-full h-full"
viewBox="0 0 1440 120"
preserveAspectRatio="none"
>
<path
d="M0,96 C240,32 480,64 720,96 C960,32 1200,64 1440,96 L1440,120 L0,120 Z"
fill="url(#gradient3)"
/>
<defs>
<linearGradient id="gradient3" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" stopColor="#99F6E4" stopOpacity="0.4" />
<stop offset="50%" stopColor="#A7F3D0" stopOpacity="0.4" />
<stop offset="100%" stopColor="#D9F99D" stopOpacity="0.4" />
</linearGradient>
</defs>
</svg>
</div>
<Contact />
</main>
<Footer />
</div>
);
}

View File

@@ -1,238 +0,0 @@
"use client";
import { motion } from "framer-motion";
import { ExternalLink, Calendar, ArrowLeft, Github as GithubIcon, Share2 } from "lucide-react";
import Link from "next/link";
import { useEffect } from "react";
import ReactMarkdown from "react-markdown";
export type ProjectDetailData = {
id: number;
slug: string;
title: string;
description: string;
content: string;
tags: string[];
featured: boolean;
category: string;
date: string;
github?: string | null;
live?: string | null;
imageUrl?: string | null;
};
export default function ProjectDetailClient({
project,
locale,
}: {
project: ProjectDetailData;
locale: string;
}) {
// Track page view (non-blocking)
useEffect(() => {
try {
navigator.sendBeacon?.(
"/api/analytics/track",
new Blob(
[
JSON.stringify({
type: "pageview",
projectId: project.id.toString(),
page: `/${locale}/projects/${project.slug}`,
}),
],
{ type: "application/json" },
),
);
} catch {
// ignore
}
}, [project.id, project.slug, locale]);
return (
<div className="min-h-screen bg-[#fdfcf8] pt-32 pb-20">
<div className="max-w-4xl mx-auto px-4">
{/* Navigation */}
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.6 }}
className="mb-8"
>
<Link
href={`/${locale}/projects`}
className="inline-flex items-center space-x-2 text-stone-500 hover:text-stone-900 transition-colors group"
>
<ArrowLeft size={20} className="group-hover:-translate-x-1 transition-transform" />
<span className="font-medium">Back to Projects</span>
</Link>
</motion.div>
{/* Header & Meta */}
<motion.div
initial={{ opacity: 0, y: 30 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.8, delay: 0.1 }}
className="mb-12"
>
<div className="flex flex-col md:flex-row md:items-start md:justify-between gap-4 mb-6">
<h1 className="text-4xl md:text-6xl font-black font-sans text-stone-900 tracking-tight leading-tight">
{project.title}
</h1>
<div className="flex gap-2 shrink-0 pt-2">
{project.featured && (
<span className="px-4 py-1.5 bg-stone-900 text-stone-50 text-xs font-bold rounded-full shadow-sm">
Featured
</span>
)}
<span className="px-4 py-1.5 bg-white border border-stone-200 text-stone-600 text-xs font-medium rounded-full shadow-sm">
{project.category}
</span>
</div>
</div>
<p className="text-xl md:text-2xl text-stone-600 font-light leading-relaxed max-w-3xl mb-8">
{project.description}
</p>
<div className="flex flex-wrap items-center gap-6 text-stone-500 text-sm border-y border-stone-200 py-6">
<div className="flex items-center space-x-2">
<Calendar size={18} />
<span className="font-mono">
{new Date(project.date).toLocaleDateString(undefined, {
year: "numeric",
month: "long",
day: "numeric",
})}
</span>
</div>
<div className="h-4 w-px bg-stone-300 hidden sm:block"></div>
<div className="flex flex-wrap gap-2">
{project.tags.map((tag) => (
<span key={tag} className="text-stone-700 font-medium">
#{tag}
</span>
))}
</div>
</div>
</motion.div>
{/* Featured Image / Fallback */}
<motion.div
initial={{ opacity: 0, scale: 0.95 }}
animate={{ opacity: 1, scale: 1 }}
transition={{ duration: 0.8, delay: 0.2 }}
className="mb-16 rounded-2xl overflow-hidden shadow-2xl bg-stone-100 aspect-video relative"
>
{project.imageUrl ? (
// eslint-disable-next-line @next/next/no-img-element
<img src={project.imageUrl} alt={project.title} className="w-full h-full object-cover" />
) : (
<div className="absolute inset-0 bg-gradient-to-br from-stone-200 to-stone-300 flex items-center justify-center">
<span className="text-9xl font-serif font-bold text-stone-500/20 select-none">
{project.title.charAt(0)}
</span>
</div>
)}
</motion.div>
{/* Content & Sidebar Layout */}
<div className="grid grid-cols-1 lg:grid-cols-3 gap-12">
{/* Main Content */}
<motion.div
initial={{ opacity: 0, y: 30 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.8, delay: 0.3 }}
className="lg:col-span-2"
>
<div className="markdown prose prose-stone max-w-none prose-lg prose-headings:font-bold prose-headings:tracking-tight prose-a:text-stone-900 prose-a:decoration-stone-300 hover:prose-a:decoration-stone-900 prose-img:rounded-xl prose-img:shadow-lg">
<ReactMarkdown
components={{
h1: ({ children }) => (
<h1 className="text-3xl font-bold text-stone-900 mt-8 mb-4">{children}</h1>
),
h2: ({ children }) => (
<h2 className="text-2xl font-bold text-stone-900 mt-8 mb-4">{children}</h2>
),
p: ({ children }) => <p className="text-stone-700 leading-relaxed mb-6">{children}</p>,
li: ({ children }) => <li className="text-stone-700">{children}</li>,
code: ({ children }) => (
<code className="bg-stone-100 text-stone-800 px-1.5 py-0.5 rounded text-sm font-mono font-medium">
{children}
</code>
),
pre: ({ children }) => (
<pre className="bg-stone-900 text-stone-50 p-6 rounded-xl overflow-x-auto my-6 shadow-lg">
{children}
</pre>
),
}}
>
{project.content}
</ReactMarkdown>
</div>
</motion.div>
{/* Sidebar / Actions */}
<motion.div
initial={{ opacity: 0, x: 20 }}
animate={{ opacity: 1, x: 0 }}
transition={{ duration: 0.8, delay: 0.4 }}
className="lg:col-span-1 space-y-8"
>
<div className="bg-white/50 backdrop-blur-xl border border-white/60 p-6 rounded-2xl shadow-sm sticky top-32">
<h3 className="font-bold text-stone-900 mb-4 flex items-center gap-2">
<Share2 size={18} />
Project Links
</h3>
<div className="space-y-3">
{project.live && project.live.trim() && project.live !== "#" ? (
<a
href={project.live}
target="_blank"
rel="noopener noreferrer"
className="flex items-center justify-between w-full px-4 py-3 bg-stone-900 text-stone-50 rounded-xl font-medium hover:bg-stone-800 hover:scale-[1.02] transition-all shadow-md group"
>
<span>Live Demo</span>
<ExternalLink size={18} className="group-hover:translate-x-1 transition-transform" />
</a>
) : (
<div className="px-4 py-3 bg-stone-100 text-stone-400 rounded-xl font-medium text-sm text-center border border-stone-200 cursor-not-allowed">
Live demo not available
</div>
)}
{project.github && project.github.trim() && project.github !== "#" ? (
<a
href={project.github}
target="_blank"
rel="noopener noreferrer"
className="flex items-center justify-between w-full px-4 py-3 bg-white border border-stone-200 text-stone-700 rounded-xl font-medium hover:bg-stone-50 hover:text-stone-900 hover:border-stone-300 transition-all shadow-sm group"
>
<span>View Source</span>
<GithubIcon size={18} className="group-hover:rotate-12 transition-transform" />
</a>
) : null}
</div>
<div className="mt-8 pt-6 border-t border-stone-100">
<h4 className="text-xs font-bold text-stone-400 uppercase tracking-wider mb-3">Tech Stack</h4>
<div className="flex flex-wrap gap-2">
{project.tags.map((tag) => (
<span
key={tag}
className="px-2.5 py-1 bg-stone-100 text-stone-600 text-xs font-medium rounded-md border border-stone-200"
>
{tag}
</span>
))}
</div>
</div>
</div>
</motion.div>
</div>
</div>
</div>
);
}

View File

@@ -1,292 +0,0 @@
"use client";
import { useEffect, useMemo, useState } from "react";
import { motion } from "framer-motion";
import { ExternalLink, Github, Calendar, ArrowLeft, Search } from "lucide-react";
import Link from "next/link";
export type ProjectListItem = {
id: number;
slug: string;
title: string;
description: string;
content: string;
tags: string[];
featured: boolean;
category: string;
date: string;
github?: string | null;
live?: string | null;
imageUrl?: string | null;
};
export default function ProjectsPageClient({
projects,
locale,
}: {
projects: ProjectListItem[];
locale: string;
}) {
const [selectedCategory, setSelectedCategory] = useState("All");
const [searchQuery, setSearchQuery] = useState("");
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
}, []);
const categories = useMemo(() => {
const unique = Array.from(new Set(projects.map((p) => p.category))).filter(Boolean);
return ["All", ...unique];
}, [projects]);
const filteredProjects = useMemo(() => {
let result = projects;
if (selectedCategory !== "All") {
result = result.filter((project) => project.category === selectedCategory);
}
if (searchQuery) {
const query = searchQuery.toLowerCase();
result = result.filter(
(project) =>
project.title.toLowerCase().includes(query) ||
project.description.toLowerCase().includes(query) ||
project.tags.some((tag) => tag.toLowerCase().includes(query)),
);
}
return result;
}, [projects, selectedCategory, searchQuery]);
if (!mounted) return null;
return (
<div className="min-h-screen bg-[#fdfcf8] pt-32 pb-20">
<div className="max-w-7xl mx-auto px-4">
{/* Header */}
<motion.div
initial={{ opacity: 0, y: 30 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.8 }}
className="mb-12"
>
<Link
href={`/${locale}`}
className="inline-flex items-center space-x-2 text-stone-500 hover:text-stone-800 transition-colors mb-8 group"
>
<ArrowLeft size={20} className="group-hover:-translate-x-1 transition-transform" />
<span>Back to Home</span>
</Link>
<h1 className="text-5xl md:text-6xl font-black font-sans mb-6 text-stone-900 tracking-tight">
My Projects
</h1>
<p className="text-xl text-stone-600 max-w-3xl font-light leading-relaxed">
Explore my portfolio of projects, from web applications to mobile apps. Each project showcases different
skills and technologies.
</p>
</motion.div>
{/* Filters & Search */}
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.8, delay: 0.2 }}
className="mb-12 flex flex-col md:flex-row gap-6 justify-between items-start md:items-center"
>
{/* Categories */}
<div className="flex flex-wrap gap-2">
{categories.map((category) => (
<button
key={category}
onClick={() => setSelectedCategory(category)}
className={`px-5 py-2 rounded-full text-sm font-medium transition-all duration-200 border ${
selectedCategory === category
? "bg-stone-800 text-stone-50 border-stone-800 shadow-md"
: "bg-white text-stone-600 border-stone-200 hover:bg-stone-50 hover:border-stone-300"
}`}
>
{category}
</button>
))}
</div>
{/* Search */}
<div className="relative w-full md:w-64">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 text-stone-400" size={18} />
<input
type="text"
placeholder="Search projects..."
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className="w-full pl-10 pr-4 py-2 bg-white border border-stone-200 rounded-full text-stone-800 placeholder:text-stone-400 focus:outline-none focus:ring-2 focus:ring-stone-200 focus:border-stone-400 transition-all"
/>
</div>
</motion.div>
{/* Projects Grid */}
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
{filteredProjects.map((project, index) => (
<motion.div
key={project.id}
initial={{ opacity: 0, y: 30 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.6, delay: index * 0.1 }}
whileHover={{ y: -8 }}
className="group flex flex-col bg-white/40 backdrop-blur-xl rounded-2xl overflow-hidden border border-white/60 shadow-[0_4px_20px_rgba(0,0,0,0.02)] hover:shadow-[0_20px_40px_rgba(0,0,0,0.06)] transition-all duration-500"
>
{/* Image / Fallback / Cover Area */}
<div className="relative aspect-[16/10] overflow-hidden bg-stone-100">
{project.imageUrl ? (
<>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={project.imageUrl}
alt={project.title}
className="w-full h-full object-cover transition-transform duration-1000 ease-out group-hover:scale-110"
/>
<div className="absolute inset-0 bg-gradient-to-t from-stone-900/20 to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500" />
</>
) : (
<div className="absolute inset-0 bg-stone-200 flex items-center justify-center overflow-hidden">
<div className="absolute inset-0 bg-gradient-to-br from-stone-300 via-stone-200 to-stone-300" />
<div className="absolute top-[-20%] left-[-10%] w-[70%] h-[70%] bg-white/20 rounded-full blur-3xl animate-pulse" />
<div className="absolute bottom-[-10%] right-[-5%] w-[60%] h-[60%] bg-stone-400/10 rounded-full blur-2xl" />
<div className="relative z-10">
<span className="text-7xl font-serif font-black text-stone-800/10 group-hover:text-stone-800/20 transition-all duration-700 select-none tracking-tighter">
{project.title.charAt(0)}
</span>
</div>
</div>
)}
{/* Texture/Grain Overlay */}
<div className="absolute inset-0 opacity-[0.03] pointer-events-none mix-blend-overlay bg-[url('https://grainy-gradients.vercel.app/noise.svg')]" />
{/* Animated Shine Effect */}
<div className="absolute inset-0 translate-x-[-100%] group-hover:translate-x-[100%] transition-transform duration-1000 ease-in-out bg-gradient-to-r from-transparent via-white/20 to-transparent skew-x-[-20deg] pointer-events-none" />
{project.featured && (
<div className="absolute top-3 left-3 z-20">
<div className="px-3 py-1 bg-[#292524]/80 backdrop-blur-md text-[#fdfcf8] text-[10px] font-bold uppercase tracking-widest rounded-full shadow-sm border border-white/10">
Featured
</div>
</div>
)}
{/* Overlay Links */}
<div className="absolute inset-0 bg-stone-900/40 opacity-0 group-hover:opacity-100 transition-opacity duration-500 ease-out flex items-center justify-center gap-4 backdrop-blur-[2px] z-20 pointer-events-none">
{project.github && (
<a
href={project.github}
target="_blank"
rel="noopener noreferrer"
className="p-3 bg-white text-stone-900 rounded-full hover:scale-110 transition-all duration-300 shadow-xl border border-white/50 pointer-events-auto"
aria-label="GitHub"
onClick={(e) => e.stopPropagation()}
>
<Github size={20} />
</a>
)}
{project.live && !project.title.toLowerCase().includes("kernel panic") && (
<a
href={project.live}
target="_blank"
rel="noopener noreferrer"
className="p-3 bg-white text-stone-900 rounded-full hover:scale-110 transition-all duration-300 shadow-xl border border-white/50 pointer-events-auto"
aria-label="Live Demo"
onClick={(e) => e.stopPropagation()}
>
<ExternalLink size={20} />
</a>
)}
</div>
</div>
<div className="p-6 flex flex-col flex-1">
{/* Stretched Link covering the whole card (including image area) */}
<Link
href={`/${locale}/projects/${project.slug}`}
className="absolute inset-0 z-10"
aria-label={`View project ${project.title}`}
/>
<div className="flex items-center justify-between mb-3">
<h3 className="text-xl font-bold text-stone-900 group-hover:text-stone-600 transition-colors">
{project.title}
</h3>
<div className="flex items-center space-x-2 text-stone-400 text-xs font-mono bg-white/50 px-2 py-1 rounded border border-stone-100">
<Calendar size={12} />
<span>{new Date(project.date).getFullYear()}</span>
</div>
</div>
<p className="text-stone-600 mb-6 leading-relaxed line-clamp-3 text-sm flex-1">{project.description}</p>
<div className="flex flex-wrap gap-2 mb-6">
{project.tags.slice(0, 4).map((tag) => (
<span
key={tag}
className="px-2.5 py-1 bg-white/60 border border-stone-100 text-stone-600 text-xs font-medium rounded-md"
>
{tag}
</span>
))}
{project.tags.length > 4 && (
<span className="px-2 py-1 text-stone-400 text-xs">+ {project.tags.length - 4}</span>
)}
</div>
<div className="mt-auto pt-4 border-t border-stone-100 flex items-center justify-between relative z-20">
<div className="flex gap-3">
{project.github && (
<a
href={project.github}
target="_blank"
rel="noopener noreferrer"
className="text-stone-400 hover:text-stone-900 transition-colors relative z-20 hover:scale-110"
onClick={(e) => e.stopPropagation()}
>
<Github size={18} />
</a>
)}
{project.live && !project.title.toLowerCase().includes("kernel panic") && (
<a
href={project.live}
target="_blank"
rel="noopener noreferrer"
className="text-stone-400 hover:text-stone-900 transition-colors relative z-20 hover:scale-110"
onClick={(e) => e.stopPropagation()}
>
<ExternalLink size={18} />
</a>
)}
</div>
</div>
</div>
</motion.div>
))}
</div>
{filteredProjects.length === 0 && (
<div className="text-center py-20">
<p className="text-stone-500 text-lg">No projects found matching your criteria.</p>
<button
onClick={() => {
setSelectedCategory("All");
setSearchQuery("");
}}
className="mt-4 text-stone-800 font-medium hover:underline"
>
Clear filters
</button>
</div>
)}
</div>
</div>
);
}

View File

@@ -14,17 +14,21 @@ export async function GET(request: NextRequest) {
status: 429, status: 429,
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
...getRateLimitHeaders(ip, 20, 60000) ...getRateLimitHeaders(ip, 5, 60000)
} }
} }
); );
} }
// Admin-only endpoint: require explicit admin header AND a valid signed session token // Check admin authentication - for admin dashboard requests, we trust the session
// The middleware has already verified the admin session for /manage routes
const isAdminRequest = request.headers.get('x-admin-request') === 'true'; const isAdminRequest = request.headers.get('x-admin-request') === 'true';
if (!isAdminRequest) return NextResponse.json({ error: 'Admin access required' }, { status: 403 }); if (!isAdminRequest) {
const authError = requireSessionAuth(request); const authError = requireSessionAuth(request);
if (authError) return authError; if (authError) {
return authError;
}
}
// Check cache first (but allow bypass with cache-bust parameter) // Check cache first (but allow bypass with cache-bust parameter)
const url = new URL(request.url); const url = new URL(request.url);
@@ -41,57 +45,47 @@ export async function GET(request: NextRequest) {
const projectsResult = await projectService.getAllProjects(); const projectsResult = await projectService.getAllProjects();
const projects = projectsResult.projects || projectsResult; const projects = projectsResult.projects || projectsResult;
const performanceStats = await projectService.getPerformanceStats(); const performanceStats = await projectService.getPerformanceStats();
// Get real page view data from database
const allPageViews = await prisma.pageView.findMany({
where: {
timestamp: {
gte: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000) // Last 30 days
}
}
});
const since = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000); // Calculate bounce rate (sessions with only 1 pageview)
const pageViewsByIP = allPageViews.reduce((acc, pv) => {
const ip = pv.ip || 'unknown';
if (!acc[ip]) acc[ip] = [];
acc[ip].push(pv);
return acc;
}, {} as Record<string, typeof allPageViews>);
// Use DB aggregation instead of loading every PageView row into memory const totalSessions = Object.keys(pageViewsByIP).length;
const [totalViews, sessionsByIp, viewsByProjectRows] = await Promise.all([ const bouncedSessions = Object.values(pageViewsByIP).filter(session => session.length === 1).length;
prisma.pageView.count({ where: { timestamp: { gte: since } } }),
prisma.pageView.groupBy({
by: ['ip'],
where: {
timestamp: { gte: since },
ip: { not: null },
},
_count: { _all: true },
_min: { timestamp: true },
_max: { timestamp: true },
}),
prisma.pageView.groupBy({
by: ['projectId'],
where: {
timestamp: { gte: since },
projectId: { not: null },
},
_count: { _all: true },
}),
]);
const totalSessions = sessionsByIp.length;
const bouncedSessions = sessionsByIp.filter(s => (s as unknown as { _count?: { _all?: number } })._count?._all === 1).length;
const bounceRate = totalSessions > 0 ? Math.round((bouncedSessions / totalSessions) * 100) : 0; const bounceRate = totalSessions > 0 ? Math.round((bouncedSessions / totalSessions) * 100) : 0;
const sessionDurationsMs = sessionsByIp // Calculate average session duration (simplified - time between first and last pageview per IP)
.map(s => { const sessionDurations = Object.values(pageViewsByIP)
const count = (s as unknown as { _count?: { _all?: number } })._count?._all ?? 0; .map(session => {
if (count < 2) return 0; if (session.length < 2) return 0;
const minTs = (s as unknown as { _min?: { timestamp?: Date | null } })._min?.timestamp; const sorted = session.sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
const maxTs = (s as unknown as { _max?: { timestamp?: Date | null } })._max?.timestamp; return sorted[sorted.length - 1].timestamp.getTime() - sorted[0].timestamp.getTime();
if (!minTs || !maxTs) return 0;
return maxTs.getTime() - minTs.getTime();
}) })
.filter(ms => ms > 0); .filter(d => d > 0);
const avgSessionDuration = sessionDurations.length > 0
const avgSessionDuration = sessionDurationsMs.length > 0 ? Math.round(sessionDurations.reduce((a, b) => a + b, 0) / sessionDurations.length / 1000) // in seconds
? Math.round(sessionDurationsMs.reduce((a, b) => a + b, 0) / sessionDurationsMs.length / 1000)
: 0; : 0;
const totalUsers = totalSessions; // Get total unique users (unique IPs)
const totalUsers = new Set(allPageViews.map(pv => pv.ip).filter(Boolean)).size;
const viewsByProject = viewsByProjectRows.reduce((acc, row) => { // Calculate real views from PageView table
const projectId = row.projectId as number | null; const viewsByProject = allPageViews.reduce((acc, pv) => {
if (projectId != null) { if (pv.projectId) {
acc[projectId] = (row as unknown as { _count?: { _all?: number } })._count?._all ?? 0; acc[pv.projectId] = (acc[pv.projectId] || 0) + 1;
} }
return acc; return acc;
}, {} as Record<number, number>); }, {} as Record<number, number>);
@@ -102,7 +96,7 @@ export async function GET(request: NextRequest) {
totalProjects: projects.length, totalProjects: projects.length,
publishedProjects: projects.filter(p => p.published).length, publishedProjects: projects.filter(p => p.published).length,
featuredProjects: projects.filter(p => p.featured).length, featuredProjects: projects.filter(p => p.featured).length,
totalViews, // Real views from PageView table totalViews: allPageViews.length, // Real views from PageView table
totalLikes: 0, // Not implemented - no like buttons totalLikes: 0, // Not implemented - no like buttons
totalShares: 0, // Not implemented - no share buttons totalShares: 0, // Not implemented - no share buttons
avgLighthouse: (() => { avgLighthouse: (() => {
@@ -147,14 +141,14 @@ export async function GET(request: NextRequest) {
? Math.round(projectsWithPerf.reduce((sum, p) => sum + ((p.performance as Record<string, unknown>)?.lighthouse as number || 0), 0) / projectsWithPerf.length) ? Math.round(projectsWithPerf.reduce((sum, p) => sum + ((p.performance as Record<string, unknown>)?.lighthouse as number || 0), 0) / projectsWithPerf.length)
: 0; : 0;
})(), })(),
totalViews, // Real total views totalViews: allPageViews.length, // Real total views
totalLikes: 0, totalLikes: 0,
totalShares: 0 totalShares: 0
}, },
metrics: { metrics: {
bounceRate, bounceRate,
avgSessionDuration, avgSessionDuration,
pagesPerSession: totalSessions > 0 ? (totalViews / totalSessions).toFixed(1) : '0', pagesPerSession: totalSessions > 0 ? (allPageViews.length / totalSessions).toFixed(1) : '0',
newUsers: totalUsers, newUsers: totalUsers,
totalUsers totalUsers
} }

View File

@@ -4,11 +4,14 @@ import { requireSessionAuth } from '@/lib/auth';
export async function GET(request: NextRequest) { export async function GET(request: NextRequest) {
try { try {
// Admin-only endpoint // Check admin authentication - for admin dashboard requests, we trust the session
const isAdminRequest = request.headers.get('x-admin-request') === 'true'; const isAdminRequest = request.headers.get('x-admin-request') === 'true';
if (!isAdminRequest) return NextResponse.json({ error: 'Admin access required' }, { status: 403 }); if (!isAdminRequest) {
const authError = requireSessionAuth(request); const authError = requireSessionAuth(request);
if (authError) return authError; if (authError) {
return authError;
}
}
// Get performance data from database // Get performance data from database
const pageViews = await prisma.pageView.findMany({ const pageViews = await prisma.pageView.findMany({

View File

@@ -22,9 +22,12 @@ export async function POST(request: NextRequest) {
// Check admin authentication // Check admin authentication
const isAdminRequest = request.headers.get('x-admin-request') === 'true'; const isAdminRequest = request.headers.get('x-admin-request') === 'true';
if (!isAdminRequest) return NextResponse.json({ error: 'Admin access required' }, { status: 403 }); if (!isAdminRequest) {
const authError = requireSessionAuth(request); const authError = requireSessionAuth(request);
if (authError) return authError; if (authError) {
return authError;
}
}
const { type } = await request.json(); const { type } = await request.json();

View File

@@ -26,20 +26,7 @@ export async function POST(request: NextRequest) {
// Track page view // Track page view
if (type === 'pageview' && page) { if (type === 'pageview' && page) {
let projectIdNum: number | null = null; const projectIdNum = projectId ? parseInt(projectId.toString()) : null;
if (projectId != null) {
const raw = projectId.toString();
const parsed = parseInt(raw, 10);
if (Number.isFinite(parsed)) {
projectIdNum = parsed;
} else {
const bySlug = await prisma.project.findFirst({
where: { slug: raw },
select: { id: true },
});
projectIdNum = bySlug?.id ?? null;
}
}
// Create page view record // Create page view record
await prisma.pageView.create({ await prisma.pageView.create({
@@ -96,7 +83,7 @@ export async function POST(request: NextRequest) {
where: { where: {
OR: [ OR: [
{ id: parseInt(slug) || 0 }, { id: parseInt(slug) || 0 },
{ slug } { title: { contains: slug, mode: 'insensitive' } }
] ]
} }
}); });

View File

@@ -37,13 +37,7 @@ export async function POST(request: NextRequest) {
} }
// Get admin credentials from environment // Get admin credentials from environment
const adminAuth = process.env.ADMIN_BASIC_AUTH; const adminAuth = process.env.ADMIN_BASIC_AUTH || 'admin:default_password_change_me';
if (!adminAuth || adminAuth.trim() === '' || adminAuth === 'admin:default_password_change_me') {
return new NextResponse(
JSON.stringify({ error: 'Admin auth is not configured' }),
{ status: 503, headers: { 'Content-Type': 'application/json' } }
);
}
const [, expectedPassword] = adminAuth.split(':'); const [, expectedPassword] = adminAuth.split(':');
// Secure password comparison using constant-time comparison // Secure password comparison using constant-time comparison
@@ -54,14 +48,22 @@ export async function POST(request: NextRequest) {
// Use constant-time comparison to prevent timing attacks // Use constant-time comparison to prevent timing attacks
if (passwordBuffer.length === expectedBuffer.length && if (passwordBuffer.length === expectedBuffer.length &&
crypto.timingSafeEqual(passwordBuffer, expectedBuffer)) { crypto.timingSafeEqual(passwordBuffer, expectedBuffer)) {
const { createSessionToken } = await import('@/lib/auth'); // Generate cryptographically secure session token
const sessionToken = createSessionToken(request); const timestamp = Date.now();
if (!sessionToken) { const randomBytes = crypto.randomBytes(32);
return new NextResponse( const randomString = randomBytes.toString('hex');
JSON.stringify({ error: 'Session secret not configured' }),
{ status: 503, headers: { 'Content-Type': 'application/json' } } // Create session data
); const sessionData = {
} timestamp,
random: randomString,
ip: ip,
userAgent: request.headers.get('user-agent') || 'unknown'
};
// Encode session data (base64 is sufficient for this use case)
const sessionJson = JSON.stringify(sessionData);
const sessionToken = Buffer.from(sessionJson).toString('base64');
return new NextResponse( return new NextResponse(
JSON.stringify({ JSON.stringify({

View File

@@ -1,5 +1,4 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { verifySessionToken } from '@/lib/auth';
export async function POST(request: NextRequest) { export async function POST(request: NextRequest) {
try { try {
@@ -21,26 +20,70 @@ export async function POST(request: NextRequest) {
); );
} }
const valid = verifySessionToken(request, sessionToken); // Decode and validate session token
if (!valid) { try {
const decodedJson = atob(sessionToken);
const sessionData = JSON.parse(decodedJson);
// Validate session data structure
if (!sessionData.timestamp || !sessionData.random || !sessionData.ip || !sessionData.userAgent) {
return new NextResponse(
JSON.stringify({ valid: false, error: 'Invalid session token structure' }),
{ status: 401, headers: { 'Content-Type': 'application/json' } }
);
}
// Check if session is still valid (2 hours)
const sessionTime = sessionData.timestamp;
const now = Date.now();
const sessionDuration = 2 * 60 * 60 * 1000; // 2 hours
if (now - sessionTime > sessionDuration) {
return new NextResponse(
JSON.stringify({ valid: false, error: 'Session expired' }),
{ status: 401, headers: { 'Content-Type': 'application/json' } }
);
}
// Validate IP address (optional, but good security practice)
const currentIp = request.headers.get('x-forwarded-for') || request.headers.get('x-real-ip') || 'unknown';
if (sessionData.ip !== currentIp) {
// Log potential session hijacking attempt
console.warn(`Session IP mismatch: expected ${sessionData.ip}, got ${currentIp}`);
return new NextResponse(
JSON.stringify({ valid: false, error: 'Session validation failed' }),
{ status: 401, headers: { 'Content-Type': 'application/json' } }
);
}
// Validate User-Agent (optional)
const currentUserAgent = request.headers.get('user-agent') || 'unknown';
if (sessionData.userAgent !== currentUserAgent) {
console.warn(`Session User-Agent mismatch`);
return new NextResponse(
JSON.stringify({ valid: false, error: 'Session validation failed' }),
{ status: 401, headers: { 'Content-Type': 'application/json' } }
);
}
return new NextResponse( return new NextResponse(
JSON.stringify({ valid: false, error: 'Session expired or invalid' }), JSON.stringify({ valid: true, message: 'Session valid' }),
{
status: 200,
headers: {
'Content-Type': 'application/json',
'X-Content-Type-Options': 'nosniff',
'X-Frame-Options': 'DENY',
'X-XSS-Protection': '1; mode=block'
}
}
);
} catch {
return new NextResponse(
JSON.stringify({ valid: false, error: 'Invalid session token format' }),
{ status: 401, headers: { 'Content-Type': 'application/json' } } { status: 401, headers: { 'Content-Type': 'application/json' } }
); );
} }
return new NextResponse(
JSON.stringify({ valid: true, message: 'Session valid' }),
{
status: 200,
headers: {
'Content-Type': 'application/json',
'X-Content-Type-Options': 'nosniff',
'X-Frame-Options': 'DENY',
'X-XSS-Protection': '1; mode=block'
}
}
);
} catch { } catch {
return new NextResponse( return new NextResponse(
JSON.stringify({ valid: false, error: 'Internal server error' }), JSON.stringify({ valid: false, error: 'Internal server error' }),

View File

@@ -1,7 +1,9 @@
import { type NextRequest, NextResponse } from "next/server"; import { type NextRequest, NextResponse } from "next/server";
import { PrismaClient } from '@prisma/client';
import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library'; import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library';
import { checkRateLimit, getRateLimitHeaders, requireSessionAuth } from '@/lib/auth'; import { checkRateLimit, getRateLimitHeaders } from '@/lib/auth';
import { prisma } from "@/lib/prisma";
const prisma = new PrismaClient();
export async function PUT( export async function PUT(
request: NextRequest, request: NextRequest,
@@ -23,11 +25,6 @@ export async function PUT(
); );
} }
const isAdminRequest = request.headers.get('x-admin-request') === 'true';
if (!isAdminRequest) return NextResponse.json({ error: 'Admin access required' }, { status: 403 });
const authError = requireSessionAuth(request);
if (authError) return authError;
const resolvedParams = await params; const resolvedParams = await params;
const id = parseInt(resolvedParams.id); const id = parseInt(resolvedParams.id);
const body = await request.json(); const body = await request.json();
@@ -96,11 +93,6 @@ export async function DELETE(
); );
} }
const isAdminRequest = request.headers.get('x-admin-request') === 'true';
if (!isAdminRequest) return NextResponse.json({ error: 'Admin access required' }, { status: 403 });
const authError = requireSessionAuth(request);
if (authError) return authError;
const resolvedParams = await params; const resolvedParams = await params;
const id = parseInt(resolvedParams.id); const id = parseInt(resolvedParams.id);

View File

@@ -1,15 +1,10 @@
import { type NextRequest, NextResponse } from "next/server"; import { type NextRequest, NextResponse } from "next/server";
import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library'; import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library';
import { checkRateLimit, getRateLimitHeaders, requireSessionAuth } from '@/lib/auth'; import { checkRateLimit, getRateLimitHeaders } from '@/lib/auth';
import { prisma } from '@/lib/prisma'; import { prisma } from '@/lib/prisma';
export async function GET(request: NextRequest) { export async function GET(request: NextRequest) {
try { try {
const isAdminRequest = request.headers.get('x-admin-request') === 'true';
if (!isAdminRequest) return NextResponse.json({ error: 'Admin access required' }, { status: 403 });
const authError = requireSessionAuth(request);
if (authError) return authError;
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);
const filter = searchParams.get('filter') || 'all'; const filter = searchParams.get('filter') || 'all';
const limit = parseInt(searchParams.get('limit') || '50'); const limit = parseInt(searchParams.get('limit') || '50');

View File

@@ -1,25 +0,0 @@
import { NextRequest, NextResponse } from "next/server";
import { getContentByKey } from "@/lib/content";
export async function GET(request: NextRequest) {
const { searchParams } = new URL(request.url);
const key = searchParams.get("key");
const locale = searchParams.get("locale") || "en";
if (!key) {
return NextResponse.json({ error: "key is required" }, { status: 400 });
}
try {
const translation = await getContentByKey({ key, locale });
if (!translation) return NextResponse.json({ content: null });
return NextResponse.json({ content: translation });
} catch (error) {
// If DB isn't migrated/available, fail soft so the UI can fall back to next-intl strings.
if (process.env.NODE_ENV === "development") {
console.warn("Content API failed; returning null content:", error);
}
return NextResponse.json({ content: null });
}
}

View File

@@ -1,55 +0,0 @@
import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
import { requireSessionAuth } from "@/lib/auth";
import { upsertContentByKey } from "@/lib/content";
export async function GET(request: NextRequest) {
const isAdminRequest = request.headers.get("x-admin-request") === "true";
if (!isAdminRequest) return NextResponse.json({ error: "Admin access required" }, { status: 403 });
const authError = requireSessionAuth(request);
if (authError) return authError;
const pages = await prisma.contentPage.findMany({
orderBy: { key: "asc" },
include: {
translations: {
select: { locale: true, updatedAt: true, title: true, slug: true },
},
},
});
return NextResponse.json({ pages });
}
export async function POST(request: NextRequest) {
const isAdminRequest = request.headers.get("x-admin-request") === "true";
if (!isAdminRequest) return NextResponse.json({ error: "Admin access required" }, { status: 403 });
const authError = requireSessionAuth(request);
if (authError) return authError;
const body = await request.json();
const { key, locale, title, slug, content, metaDescription, keywords } = body as Record<string, unknown>;
if (!key || typeof key !== "string") {
return NextResponse.json({ error: "key is required" }, { status: 400 });
}
if (!locale || typeof locale !== "string") {
return NextResponse.json({ error: "locale is required" }, { status: 400 });
}
if (!content || typeof content !== "object") {
return NextResponse.json({ error: "content (JSON) is required" }, { status: 400 });
}
const saved = await upsertContentByKey({
key,
locale,
title: typeof title === "string" ? title : null,
slug: typeof slug === "string" ? slug : null,
content,
metaDescription: typeof metaDescription === "string" ? metaDescription : null,
keywords: typeof keywords === "string" ? keywords : null,
});
return NextResponse.json({ saved });
}

View File

@@ -2,7 +2,6 @@ import { type NextRequest, NextResponse } from "next/server";
import nodemailer from "nodemailer"; import nodemailer from "nodemailer";
import SMTPTransport from "nodemailer/lib/smtp-transport"; import SMTPTransport from "nodemailer/lib/smtp-transport";
import Mail from "nodemailer/lib/mailer"; import Mail from "nodemailer/lib/mailer";
import { checkRateLimit, getRateLimitHeaders, getClientIp, requireSessionAuth } from "@/lib/auth";
const BRAND = { const BRAND = {
siteUrl: "https://dk0.dev", siteUrl: "https://dk0.dev",
@@ -173,10 +172,9 @@ const emailTemplates = {
}, },
reply: { reply: {
subject: "Antwort auf deine Nachricht 📧", subject: "Antwort auf deine Nachricht 📧",
template: (name: string, originalMessage: string, responseMessage: string) => { template: (name: string, originalMessage: string) => {
const safeName = escapeHtml(name); const safeName = escapeHtml(name);
const safeOriginal = nl2br(escapeHtml(originalMessage)); const safeMsg = nl2br(escapeHtml(originalMessage));
const safeResponse = nl2br(escapeHtml(responseMessage));
return baseEmail({ return baseEmail({
title: `Antwort für ${safeName}`, title: `Antwort für ${safeName}`,
subtitle: "Neue Nachricht", subtitle: "Neue Nachricht",
@@ -191,16 +189,7 @@ const emailTemplates = {
<div style="font-size:12px;letter-spacing:0.08em;text-transform:uppercase;font-weight:800;color:#57534e;">Antwort</div> <div style="font-size:12px;letter-spacing:0.08em;text-transform:uppercase;font-weight:800;color:#57534e;">Antwort</div>
</div> </div>
<div style="padding:16px;line-height:1.65;color:${BRAND.text};font-size:14px;border-left:4px solid ${BRAND.mint};"> <div style="padding:16px;line-height:1.65;color:${BRAND.text};font-size:14px;border-left:4px solid ${BRAND.mint};">
${safeResponse} ${safeMsg}
</div>
</div>
<div style="margin-top:16px;background:${BRAND.bg};border:1px solid ${BRAND.border};border-radius:16px;overflow:hidden;">
<div style="padding:14px 16px;background:${BRAND.sand};border-bottom:1px solid ${BRAND.border};">
<div style="font-size:12px;letter-spacing:0.08em;text-transform:uppercase;font-weight:800;color:#57534e;">Deine ursprüngliche Nachricht</div>
</div>
<div style="padding:16px;line-height:1.65;color:${BRAND.text};font-size:14px;border-left:4px solid ${BRAND.border};">
${safeOriginal}
</div> </div>
</div> </div>
`.trim(), `.trim(),
@@ -211,39 +200,25 @@ const emailTemplates = {
export async function POST(request: NextRequest) { export async function POST(request: NextRequest) {
try { try {
const isAdminRequest = request.headers.get("x-admin-request") === "true";
if (!isAdminRequest) return NextResponse.json({ error: "Admin access required" }, { status: 403 });
const authError = requireSessionAuth(request);
if (authError) return authError;
const ip = getClientIp(request);
if (!checkRateLimit(ip, 10, 60000)) {
return NextResponse.json(
{ error: "Rate limit exceeded" },
{ status: 429, headers: { ...getRateLimitHeaders(ip, 10, 60000) } },
);
}
const body = (await request.json()) as { const body = (await request.json()) as {
to: string; to: string;
name: string; name: string;
template: 'welcome' | 'project' | 'quick' | 'reply'; template: 'welcome' | 'project' | 'quick' | 'reply';
originalMessage: string; originalMessage: string;
response?: string;
}; };
const { to, name, template, originalMessage, response } = body; const { to, name, template, originalMessage } = body;
console.log('📧 Email response request:', { to, name, template, messageLength: originalMessage.length });
// Validate input // Validate input
if (!to || !name || !template || !originalMessage) { if (!to || !name || !template || !originalMessage) {
console.error('❌ Validation failed: Missing required fields');
return NextResponse.json( return NextResponse.json(
{ error: "Alle Felder sind erforderlich" }, { error: "Alle Felder sind erforderlich" },
{ status: 400 }, { status: 400 },
); );
} }
if (template === "reply" && (!response || !response.trim())) {
return NextResponse.json({ error: "Antworttext ist erforderlich" }, { status: 400 });
}
// Validate email format // Validate email format
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
@@ -257,6 +232,7 @@ export async function POST(request: NextRequest) {
// Check if template exists // Check if template exists
if (!emailTemplates[template]) { if (!emailTemplates[template]) {
console.error('❌ Validation failed: Invalid template');
return NextResponse.json( return NextResponse.json(
{ error: "Ungültiges Template" }, { error: "Ungültiges Template" },
{ status: 400 }, { status: 400 },
@@ -298,7 +274,9 @@ export async function POST(request: NextRequest) {
// Verify transport configuration // Verify transport configuration
try { try {
await transport.verify(); await transport.verify();
} catch (_verifyError) { console.log('✅ SMTP connection verified successfully');
} catch (verifyError) {
console.error('❌ SMTP verification failed:', verifyError);
return NextResponse.json( return NextResponse.json(
{ error: "E-Mail-Server-Verbindung fehlgeschlagen" }, { error: "E-Mail-Server-Verbindung fehlgeschlagen" },
{ status: 500 }, { status: 500 },
@@ -306,27 +284,19 @@ export async function POST(request: NextRequest) {
} }
const selectedTemplate = emailTemplates[template]; const selectedTemplate = emailTemplates[template];
let html: string;
if (template === "reply") {
html = emailTemplates.reply.template(name, originalMessage, response || "");
} else {
// Narrow the template type so TS knows this is not the 3-arg reply template
const nonReplyTemplate = template as Exclude<typeof template, "reply">;
html = emailTemplates[nonReplyTemplate].template(name, originalMessage);
}
const mailOptions: Mail.Options = { const mailOptions: Mail.Options = {
from: `"Dennis Konkol" <${user}>`, from: `"Dennis Konkol" <${user}>`,
to: to, to: to,
replyTo: "contact@dk0.dev", replyTo: "contact@dk0.dev",
subject: selectedTemplate.subject, subject: selectedTemplate.subject,
html, html: selectedTemplate.template(name, originalMessage),
text: ` text: `
Hallo ${name}! Hallo ${name}!
Vielen Dank für deine Nachricht: Vielen Dank für deine Nachricht:
${originalMessage} ${originalMessage}
${template === "reply" ? `\nAntwort:\n${response || ""}\n` : "\nIch werde mich so schnell wie möglich bei dir melden.\n"} Ich werde mich so schnell wie möglich bei dir melden.
Beste Grüße, Beste Grüße,
Dennis Konkol Dennis Konkol
@@ -336,18 +306,23 @@ contact@dk0.dev
`, `,
}; };
console.log('📤 Sending templated email...');
const sendMailPromise = () => const sendMailPromise = () =>
new Promise<string>((resolve, reject) => { new Promise<string>((resolve, reject) => {
transport.sendMail(mailOptions, function (err, info) { transport.sendMail(mailOptions, function (err, info) {
if (!err) { if (!err) {
console.log('✅ Templated email sent successfully:', info.response);
resolve(info.response); resolve(info.response);
} else { } else {
console.error("❌ Error sending templated email:", err);
reject(err.message); reject(err.message);
} }
}); });
}); });
const result = await sendMailPromise(); const result = await sendMailPromise();
console.log('🎉 Templated email process completed successfully');
return NextResponse.json({ return NextResponse.json({
message: "Template-E-Mail erfolgreich gesendet", message: "Template-E-Mail erfolgreich gesendet",
@@ -356,6 +331,7 @@ contact@dk0.dev
}); });
} catch (err) { } catch (err) {
console.error("❌ Unexpected error in templated email API:", err);
return NextResponse.json({ return NextResponse.json({
error: "Fehler beim Senden der Template-E-Mail", error: "Fehler beim Senden der Template-E-Mail",
details: err instanceof Error ? err.message : 'Unbekannter Fehler' details: err instanceof Error ? err.message : 'Unbekannter Fehler'

View File

@@ -2,8 +2,10 @@ import { type NextRequest, NextResponse } from "next/server";
import nodemailer from "nodemailer"; import nodemailer from "nodemailer";
import SMTPTransport from "nodemailer/lib/smtp-transport"; import SMTPTransport from "nodemailer/lib/smtp-transport";
import Mail from "nodemailer/lib/mailer"; import Mail from "nodemailer/lib/mailer";
import { PrismaClient } from '@prisma/client';
import { checkRateLimit, getRateLimitHeaders } from '@/lib/auth'; import { checkRateLimit, getRateLimitHeaders } from '@/lib/auth';
import { prisma } from "@/lib/prisma";
const prisma = new PrismaClient();
// Sanitize input to prevent XSS // Sanitize input to prevent XSS
function sanitizeInput(input: string, maxLength: number = 10000): string { function sanitizeInput(input: string, maxLength: number = 10000): string {
@@ -93,6 +95,12 @@ export async function POST(request: NextRequest) {
const user = process.env.MY_EMAIL ?? ""; const user = process.env.MY_EMAIL ?? "";
const pass = process.env.MY_PASSWORD ?? ""; const pass = process.env.MY_PASSWORD ?? "";
console.log('🔑 Environment check:', {
hasEmail: !!user,
hasPassword: !!pass,
emailHost: user.split('@')[1] || 'unknown'
});
if (!user || !pass) { if (!user || !pass) {
console.error("❌ Missing email/password environment variables"); console.error("❌ Missing email/password environment variables");
return NextResponse.json( return NextResponse.json(
@@ -115,12 +123,11 @@ export async function POST(request: NextRequest) {
connectionTimeout: 30000, // 30 seconds connectionTimeout: 30000, // 30 seconds
greetingTimeout: 30000, // 30 seconds greetingTimeout: 30000, // 30 seconds
socketTimeout: 60000, // 60 seconds socketTimeout: 60000, // 60 seconds
// TLS hardening (allow insecure/self-signed only when explicitly enabled) // Additional TLS options for better compatibility
tls: tls: {
process.env.SMTP_ALLOW_INSECURE_TLS === "true" || rejectUnauthorized: false, // Allow self-signed certificates
process.env.SMTP_ALLOW_SELF_SIGNED === "true" ciphers: 'SSLv3'
? { rejectUnauthorized: false } }
: { rejectUnauthorized: true, minVersion: "TLSv1.2" },
}; };
// Creating transport with configured options // Creating transport with configured options

View File

@@ -1,58 +1,66 @@
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import NodeCache from "node-cache"; import NodeCache from "node-cache";
import { prisma } from "@/lib/prisma";
// Use a dynamic import for node-fetch so tests that mock it (via jest.mock) are respected
async function getFetch() {
try {
const mod = await import("node-fetch");
// support both CJS and ESM interop
return (mod as { default: unknown }).default ?? mod;
} catch (_err) {
return globalThis.fetch;
}
}
export const runtime = "nodejs"; // Force Node runtime export const runtime = "nodejs"; // Force Node runtime
const GHOST_API_URL = process.env.GHOST_API_URL;
const GHOST_API_KEY = process.env.GHOST_API_KEY;
const cache = new NodeCache({ stdTTL: 300 }); // Cache für 5 Minuten const cache = new NodeCache({ stdTTL: 300 }); // Cache für 5 Minuten
type LegacyPost = { type GhostPost = {
slug: string; slug: string;
id: string; id: string;
title: string; title: string;
meta_description: string | null; feature_image: string;
visibility: string;
published_at: string;
updated_at: string; updated_at: string;
html: string;
reading_time: number;
meta_description: string;
}; };
type LegacyPostsResponse = { type GhostPostsResponse = {
posts: Array<LegacyPost>; posts: Array<GhostPost>;
}; };
export async function GET() { export async function GET() {
const cacheKey = "projects:legacyPosts"; const cacheKey = "ghostPosts";
const cachedPosts = cache.get<LegacyPostsResponse>(cacheKey); const cachedPosts = cache.get<GhostPostsResponse>(cacheKey);
if (cachedPosts) { if (cachedPosts) {
return NextResponse.json(cachedPosts); return NextResponse.json(cachedPosts);
} }
try { try {
const projects = await prisma.project.findMany({ const fetchFn = await getFetch();
where: { published: true }, const response = await (fetchFn as unknown as typeof fetch)(
orderBy: { updatedAt: "desc" }, `${GHOST_API_URL}/ghost/api/content/posts/?key=${GHOST_API_KEY}&limit=all`,
select: { );
id: true, const posts: GhostPostsResponse =
slug: true, (await response.json()) as GhostPostsResponse;
title: true,
updatedAt: true,
metaDescription: true,
},
});
const payload: LegacyPostsResponse = { if (!posts || !posts.posts) {
posts: projects.map((p) => ({ console.error("Invalid posts data");
id: String(p.id), return NextResponse.json([]);
slug: p.slug, }
title: p.title,
meta_description: p.metaDescription ?? null,
updated_at: (p.updatedAt ?? new Date()).toISOString(),
})),
};
cache.set(cacheKey, payload); cache.set(cacheKey, posts); // Daten im Cache speichern
return NextResponse.json(payload);
return NextResponse.json(posts);
} catch (error) { } catch (error) {
console.error("Failed to fetch projects:", error); console.error("Failed to fetch posts from Ghost:", error);
return NextResponse.json( return NextResponse.json(
{ error: "Failed to fetch projects" }, { error: "Failed to fetch projects" },
{ status: 500 }, { status: 500 },

View File

@@ -1,8 +1,10 @@
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
export const runtime = "nodejs"; // Force Node runtime export const runtime = "nodejs"; // Force Node runtime
const GHOST_API_URL = process.env.GHOST_API_URL;
const GHOST_API_KEY = process.env.GHOST_API_KEY;
export async function GET(request: Request) { export async function GET(request: Request) {
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);
const slug = searchParams.get("slug"); const slug = searchParams.get("slug");
@@ -12,37 +14,59 @@ export async function GET(request: Request) {
} }
try { try {
const project = await prisma.project.findUnique({ // Debug: show whether fetch is present/mocked
where: { slug },
select: {
id: true,
slug: true,
title: true,
updatedAt: true,
metaDescription: true,
description: true,
content: true,
},
});
if (!project) { /* eslint-disable @typescript-eslint/no-explicit-any */
return NextResponse.json({ posts: [] }, { status: 200 }); console.log(
"DEBUG fetch in fetchProject:",
typeof (globalThis as any).fetch,
"globalIsMock:",
!!(globalThis as any).fetch?._isMockFunction,
);
// Try global fetch first (as tests often mock it). If it fails or returns undefined,
// fall back to dynamically importing node-fetch.
let response: any;
if (typeof (globalThis as any).fetch === "function") {
try {
response = await (globalThis as any).fetch(
`${GHOST_API_URL}/ghost/api/content/posts/slug/${slug}/?key=${GHOST_API_KEY}`,
);
} catch (_e) {
response = undefined;
}
} }
// Legacy shape (Ghost-like) for compatibility with older frontend/tests. if (!response || typeof response.ok === "undefined") {
return NextResponse.json({ try {
posts: [ const mod = await import("node-fetch");
{ const nodeFetch = (mod as any).default ?? mod;
id: String(project.id), response = await (nodeFetch as any)(
title: project.title, `${GHOST_API_URL}/ghost/api/content/posts/slug/${slug}/?key=${GHOST_API_KEY}`,
meta_description: project.metaDescription ?? project.description ?? "", );
slug: project.slug, } catch (_err) {
updated_at: (project.updatedAt ?? new Date()).toISOString(), response = undefined;
}, }
], }
}); /* eslint-enable @typescript-eslint/no-explicit-any */
// Debug: inspect the response returned from the fetch
// Debug: inspect the response returned from the fetch
console.log("DEBUG fetch response:", response);
if (!response || !response.ok) {
throw new Error(
`Failed to fetch post: ${response?.statusText ?? "no response"}`,
);
}
const post = await response.json();
return NextResponse.json(post);
} catch (error) { } catch (error) {
console.error("Failed to fetch project:", error); console.error("Failed to fetch post from Ghost:", error);
return NextResponse.json( return NextResponse.json(
{ error: "Failed to fetch project" }, { error: "Failed to fetch project" },
{ status: 500 }, { status: 500 },

View File

@@ -1,5 +1,4 @@
import { NextRequest, NextResponse } from "next/server"; import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
/** /**
* POST /api/n8n/generate-image * POST /api/n8n/generate-image
@@ -58,16 +57,23 @@ export async function POST(req: NextRequest) {
); );
} }
const projectIdNum = typeof projectId === "string" ? parseInt(projectId, 10) : Number(projectId); // Fetch project data first (needed for the new webhook format)
if (!Number.isFinite(projectIdNum)) { const projectResponse = await fetch(
return NextResponse.json({ error: "projectId must be a number" }, { status: 400 }); `${process.env.NEXT_PUBLIC_API_URL || "http://localhost:3000"}/api/projects/${projectId}`,
{
method: "GET",
cache: "no-store",
},
);
if (!projectResponse.ok) {
return NextResponse.json(
{ error: "Project not found" },
{ status: 404 },
);
} }
// Fetch project data directly (avoid HTTP self-calls) const project = await projectResponse.json();
const project = await prisma.project.findUnique({ where: { id: projectIdNum } });
if (!project) {
return NextResponse.json({ error: "Project not found" }, { status: 404 });
}
// Optional: Check if project already has an image // Optional: Check if project already has an image
if (!regenerate) { if (!regenerate) {
@@ -77,7 +83,7 @@ export async function POST(req: NextRequest) {
success: true, success: true,
message: message:
"Project already has an image. Use regenerate=true to force regeneration.", "Project already has an image. Use regenerate=true to force regeneration.",
projectId: projectIdNum, projectId: projectId,
existingImageUrl: project.imageUrl, existingImageUrl: project.imageUrl,
regenerated: false, regenerated: false,
}, },
@@ -100,7 +106,7 @@ export async function POST(req: NextRequest) {
}), }),
}, },
body: JSON.stringify({ body: JSON.stringify({
projectId: projectIdNum, projectId: projectId,
projectData: { projectData: {
title: project.title || "Unknown Project", title: project.title || "Unknown Project",
category: project.category || "Technology", category: project.category || "Technology",
@@ -190,13 +196,22 @@ export async function POST(req: NextRequest) {
// If we got an image URL, we should update the project with it // If we got an image URL, we should update the project with it
if (imageUrl) { if (imageUrl) {
try { // Update project with the new image URL
await prisma.project.update({ const updateResponse = await fetch(
where: { id: projectIdNum }, `${process.env.NEXT_PUBLIC_API_URL || "http://localhost:3000"}/api/projects/${projectId}`,
data: { imageUrl, updatedAt: new Date() }, {
}); method: "PUT",
} catch { headers: {
// Non-fatal: image URL can still be returned to caller "Content-Type": "application/json",
"x-admin-request": "true",
},
body: JSON.stringify({
imageUrl: imageUrl,
}),
},
);
if (!updateResponse.ok) {
console.warn("Failed to update project with image URL"); console.warn("Failed to update project with image URL");
} }
} }
@@ -205,7 +220,7 @@ export async function POST(req: NextRequest) {
{ {
success: true, success: true,
message: "AI image generation completed successfully", message: "AI image generation completed successfully",
projectId: projectIdNum, projectId: projectId,
imageUrl: imageUrl, imageUrl: imageUrl,
generatedAt: generatedAt, generatedAt: generatedAt,
fileSize: fileSize, fileSize: fileSize,
@@ -242,17 +257,23 @@ export async function GET(req: NextRequest) {
); );
} }
const projectIdNum = parseInt(projectId, 10); // Fetch project to check image status
if (!Number.isFinite(projectIdNum)) { const projectResponse = await fetch(
return NextResponse.json({ error: "projectId must be a number" }, { status: 400 }); `${process.env.NEXT_PUBLIC_API_URL || "http://localhost:3000"}/api/projects/${projectId}`,
} {
const project = await prisma.project.findUnique({ where: { id: projectIdNum } }); method: "GET",
if (!project) { cache: "no-store",
},
);
if (!projectResponse.ok) {
return NextResponse.json({ error: "Project not found" }, { status: 404 }); return NextResponse.json({ error: "Project not found" }, { status: 404 });
} }
const project = await projectResponse.json();
return NextResponse.json({ return NextResponse.json({
projectId: projectIdNum, projectId: parseInt(projectId),
title: project.title, title: project.title,
hasImage: !!project.imageUrl, hasImage: !!project.imageUrl,
imageUrl: project.imageUrl || null, imageUrl: project.imageUrl || null,

View File

@@ -1,131 +0,0 @@
// app/api/n8n/hardcover/currently-reading/route.ts
import { NextRequest, NextResponse } from "next/server";
// Cache für 5 Minuten, damit wir n8n nicht zuspammen
// Hardcover-Daten ändern sich nicht so häufig
export const revalidate = 300;
export async function GET(request: NextRequest) {
// Rate limiting for n8n hardcover endpoint
const ip =
request.headers.get("x-forwarded-for") ||
request.headers.get("x-real-ip") ||
"unknown";
const ua = request.headers.get("user-agent") || "unknown";
const { checkRateLimit } = await import('@/lib/auth');
// In dev, many requests can share ip=unknown; use UA to avoid a shared bucket.
const rateKey =
process.env.NODE_ENV === "development" && ip === "unknown"
? `ua:${ua.slice(0, 120)}`
: ip;
const maxPerMinute = process.env.NODE_ENV === "development" ? 60 : 10;
if (!checkRateLimit(rateKey, maxPerMinute, 60000)) { // requests per minute
return NextResponse.json(
{ error: 'Rate limit exceeded. Please try again later.' },
{ status: 429 }
);
}
try {
// Check if n8n webhook URL is configured
const n8nWebhookUrl = process.env.N8N_WEBHOOK_URL;
if (!n8nWebhookUrl) {
console.warn("N8N_WEBHOOK_URL not configured for hardcover endpoint");
// Return fallback if n8n is not configured
return NextResponse.json({
currentlyReading: null,
});
}
// Rufe den n8n Webhook auf
// Add timestamp to query to bypass Cloudflare cache
const webhookUrl = `${n8nWebhookUrl}/webhook/hardcover/currently-reading?t=${Date.now()}`;
console.log(`Fetching currently reading from: ${webhookUrl}`);
// Add timeout to prevent hanging requests
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 second timeout
try {
const res = await fetch(webhookUrl, {
method: "GET",
headers: {
Accept: "application/json",
...(process.env.N8N_SECRET_TOKEN && {
Authorization: `Bearer ${process.env.N8N_SECRET_TOKEN}`,
}),
...(process.env.N8N_API_KEY && {
"X-API-Key": process.env.N8N_API_KEY,
}),
},
next: { revalidate: 300 },
signal: controller.signal,
});
clearTimeout(timeoutId);
if (!res.ok) {
const errorText = await res.text().catch(() => 'Unknown error');
console.error(`n8n hardcover webhook failed: ${res.status}`, errorText);
throw new Error(`n8n error: ${res.status} - ${errorText}`);
}
const raw = await res.text().catch(() => "");
if (!raw || !raw.trim()) {
throw new Error("Empty response body received from n8n");
}
let data: unknown;
try {
data = JSON.parse(raw);
} catch (_parseError) {
// Sometimes upstream sends HTML or a partial response; include a snippet for debugging.
const snippet = raw.slice(0, 240);
throw new Error(
`Invalid JSON from n8n (${res.status}): ${snippet}${raw.length > 240 ? "…" : ""}`,
);
}
// n8n gibt oft ein Array zurück: [{...}]. Wir wollen nur das Objekt.
const readingData = Array.isArray(data) ? data[0] : data;
// Safety check: if readingData is still undefined/null (e.g. empty array), use fallback
if (!readingData) {
throw new Error("Empty data received from n8n");
}
// Ensure currentlyReading has proper structure
if (readingData.currentlyReading && typeof readingData.currentlyReading === "object") {
// Already properly formatted from n8n
} else if (readingData.currentlyReading === null || readingData.currentlyReading === undefined) {
// No reading data - keep as null
readingData.currentlyReading = null;
}
return NextResponse.json(readingData);
} catch (fetchError: unknown) {
clearTimeout(timeoutId);
if (fetchError instanceof Error && fetchError.name === 'AbortError') {
console.error("n8n hardcover webhook request timed out");
} else {
console.error("n8n hardcover webhook fetch error:", fetchError);
}
throw fetchError;
}
} catch (error: unknown) {
console.error("Error fetching n8n hardcover data:", error);
console.error("Error details:", {
message: error instanceof Error ? error.message : String(error),
stack: error instanceof Error ? error.stack : undefined,
n8nUrl: process.env.N8N_WEBHOOK_URL ? 'configured' : 'missing',
});
// Leeres Fallback-Objekt, damit die Seite nicht abstürzt
return NextResponse.json({
currentlyReading: null,
});
}
}

View File

@@ -6,21 +6,10 @@ export const revalidate = 30;
export async function GET(request: NextRequest) { export async function GET(request: NextRequest) {
// Rate limiting for n8n status endpoint // Rate limiting for n8n status endpoint
const ip = const ip = request.headers.get('x-forwarded-for') || request.headers.get('x-real-ip') || 'unknown';
request.headers.get("x-forwarded-for") ||
request.headers.get("x-real-ip") ||
"unknown";
const ua = request.headers.get("user-agent") || "unknown";
const { checkRateLimit } = await import('@/lib/auth'); const { checkRateLimit } = await import('@/lib/auth');
// In dev, many requests can share ip=unknown; use UA to avoid a shared bucket. if (!checkRateLimit(ip, 30, 60000)) { // 30 requests per minute for status
const rateKey =
process.env.NODE_ENV === "development" && ip === "unknown"
? `ua:${ua.slice(0, 120)}`
: ip;
const maxPerMinute = process.env.NODE_ENV === "development" ? 300 : 30;
if (!checkRateLimit(rateKey, maxPerMinute, 60000)) { // requests per minute
return NextResponse.json( return NextResponse.json(
{ error: 'Rate limit exceeded. Please try again later.' }, { error: 'Rate limit exceeded. Please try again later.' },
{ status: 429 } { status: 429 }
@@ -54,8 +43,7 @@ export async function GET(request: NextRequest) {
const res = await fetch(statusUrl, { const res = await fetch(statusUrl, {
method: "GET", method: "GET",
headers: { headers: {
// n8n sometimes responds with empty body; we'll parse defensively below. "Content-Type": "application/json",
Accept: "application/json",
...(process.env.N8N_SECRET_TOKEN && { ...(process.env.N8N_SECRET_TOKEN && {
Authorization: `Bearer ${process.env.N8N_SECRET_TOKEN}`, Authorization: `Bearer ${process.env.N8N_SECRET_TOKEN}`,
}), }),
@@ -72,21 +60,7 @@ export async function GET(request: NextRequest) {
throw new Error(`n8n error: ${res.status} - ${errorText}`); throw new Error(`n8n error: ${res.status} - ${errorText}`);
} }
const raw = await res.text().catch(() => ""); const data = await res.json();
if (!raw || !raw.trim()) {
throw new Error("Empty response body received from n8n");
}
let data: unknown;
try {
data = JSON.parse(raw);
} catch (_parseError) {
// Sometimes upstream sends HTML or a partial response; include a snippet for debugging.
const snippet = raw.slice(0, 240);
throw new Error(
`Invalid JSON from n8n (${res.status}): ${snippet}${raw.length > 240 ? "…" : ""}`,
);
}
// n8n gibt oft ein Array zurück: [{...}]. Wir wollen nur das Objekt. // n8n gibt oft ein Array zurück: [{...}]. Wir wollen nur das Objekt.
const statusData = Array.isArray(data) ? data[0] : data; const statusData = Array.isArray(data) ? data[0] : data;

View File

@@ -1,9 +1,8 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { prisma } from '@/lib/prisma'; import { prisma } from '@/lib/prisma';
import { apiCache } from '@/lib/cache'; import { apiCache } from '@/lib/cache';
import { checkRateLimit, getRateLimitHeaders, requireSessionAuth } from '@/lib/auth'; import { checkRateLimit, getRateLimitHeaders } from '@/lib/auth';
import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library'; import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library';
import { generateUniqueSlug } from '@/lib/slug';
export async function GET( export async function GET(
request: NextRequest, request: NextRequest,
@@ -12,9 +11,6 @@ export async function GET(
try { try {
const { id: idParam } = await params; const { id: idParam } = await params;
const id = parseInt(idParam); const id = parseInt(idParam);
if (!Number.isFinite(id)) {
return NextResponse.json({ error: 'Invalid project id' }, { status: 400 });
}
const project = await prisma.project.findUnique({ const project = await prisma.project.findUnique({
where: { id } where: { id }
@@ -78,48 +74,18 @@ export async function PUT(
{ status: 403 } { status: 403 }
); );
} }
const authError = requireSessionAuth(request);
if (authError) return authError;
const { id: idParam } = await params; const { id: idParam } = await params;
const id = parseInt(idParam); const id = parseInt(idParam);
if (!Number.isFinite(id)) {
return NextResponse.json({ error: 'Invalid project id' }, { status: 400 });
}
const data = await request.json(); const data = await request.json();
// Remove difficulty field if it exists (since we're removing it) // Remove difficulty field if it exists (since we're removing it)
const { difficulty, slug, defaultLocale, ...projectData } = data; const { difficulty, ...projectData } = data;
// Keep slug stable by default; only update if explicitly provided,
// or if the project currently has no slug (e.g. after migration).
const existing = await prisma.project.findUnique({
where: { id },
select: { slug: true, title: true },
});
const nextSlug =
typeof slug === 'string' && slug.trim()
? slug.trim()
: existing?.slug?.trim()
? existing.slug
: await generateUniqueSlug({
base: String(projectData.title || existing?.title || 'project'),
isTaken: async (candidate) => {
const found = await prisma.project.findUnique({
where: { slug: candidate },
select: { id: true },
});
return !!found && found.id !== id;
},
});
const project = await prisma.project.update({ const project = await prisma.project.update({
where: { id }, where: { id },
data: { data: {
...projectData, ...projectData,
slug: nextSlug,
defaultLocale: typeof defaultLocale === 'string' && defaultLocale ? defaultLocale : undefined,
updatedAt: new Date(), updatedAt: new Date(),
// Keep existing difficulty if not provided // Keep existing difficulty if not provided
...(difficulty ? { difficulty } : {}) ...(difficulty ? { difficulty } : {})
@@ -181,14 +147,9 @@ export async function DELETE(
{ status: 403 } { status: 403 }
); );
} }
const authError = requireSessionAuth(request);
if (authError) return authError;
const { id: idParam } = await params; const { id: idParam } = await params;
const id = parseInt(idParam); const id = parseInt(idParam);
if (!Number.isFinite(id)) {
return NextResponse.json({ error: 'Invalid project id' }, { status: 400 });
}
await prisma.project.delete({ await prisma.project.delete({
where: { id } where: { id }

View File

@@ -1,71 +0,0 @@
import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
import { requireSessionAuth } from "@/lib/auth";
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> },
) {
const isAdminRequest = request.headers.get("x-admin-request") === "true";
if (!isAdminRequest) return NextResponse.json({ error: "Admin access required" }, { status: 403 });
const authError = requireSessionAuth(request);
if (authError) return authError;
const { id: idParam } = await params;
const id = parseInt(idParam, 10);
if (!Number.isFinite(id)) return NextResponse.json({ error: "Invalid project id" }, { status: 400 });
const { searchParams } = new URL(request.url);
const locale = searchParams.get("locale") || "en";
const translation = await prisma.projectTranslation.findFirst({
where: { projectId: id, locale },
});
return NextResponse.json({ translation });
}
export async function PUT(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> },
) {
const isAdminRequest = request.headers.get("x-admin-request") === "true";
if (!isAdminRequest) return NextResponse.json({ error: "Admin access required" }, { status: 403 });
const authError = requireSessionAuth(request);
if (authError) return authError;
const { id: idParam } = await params;
const id = parseInt(idParam, 10);
if (!Number.isFinite(id)) return NextResponse.json({ error: "Invalid project id" }, { status: 400 });
const body = (await request.json()) as {
locale?: string;
title?: string;
description?: string;
};
const locale = body.locale || "en";
const title = body.title?.trim();
const description = body.description?.trim();
if (!title || !description) {
return NextResponse.json({ error: "title and description are required" }, { status: 400 });
}
const saved = await prisma.projectTranslation.upsert({
where: { projectId_locale: { projectId: id, locale } },
create: {
projectId: id,
locale,
title,
description,
},
update: {
title,
description,
},
});
return NextResponse.json({ translation: saved });
}

View File

@@ -1,47 +1,18 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextResponse } from 'next/server';
import { prisma, projectService } from '@/lib/prisma'; import { projectService } from '@/lib/prisma';
import { requireSessionAuth } from '@/lib/auth';
export async function GET(request: NextRequest) { export async function GET() {
try { try {
const isAdminRequest = request.headers.get('x-admin-request') === 'true'; // Get all projects with full data
if (!isAdminRequest) return NextResponse.json({ error: 'Admin access required' }, { status: 403 }); const projectsResult = await projectService.getAllProjects();
const authError = requireSessionAuth(request);
if (authError) return authError;
// Projects (with translations)
const projectsResult = await projectService.getAllProjects({ limit: 10000 });
const projects = projectsResult.projects || projectsResult; const projects = projectsResult.projects || projectsResult;
const projectIds = projects.map((p: { id: number }) => p.id);
const projectTranslations = await prisma.projectTranslation.findMany({
where: { projectId: { in: projectIds } },
orderBy: [{ projectId: 'asc' }, { locale: 'asc' }],
});
// CMS content pages (with translations)
const contentPages = await prisma.contentPage.findMany({
orderBy: { key: 'asc' },
include: {
translations: {
orderBy: { locale: 'asc' },
},
},
});
const siteSettings = await prisma.siteSettings.findUnique({ where: { id: 1 } });
// Format for export // Format for export
const exportData = { const exportData = {
version: '2.0', version: '1.0',
exportDate: new Date().toISOString(), exportDate: new Date().toISOString(),
siteSettings,
contentPages,
projectTranslations,
projects: projects.map(project => ({ projects: projects.map(project => ({
id: project.id, id: project.id,
slug: (project as unknown as { slug?: string }).slug,
defaultLocale: (project as unknown as { defaultLocale?: string }).defaultLocale,
title: project.title, title: project.title,
description: project.description, description: project.description,
content: project.content, content: project.content,

View File

@@ -1,309 +1,76 @@
import { NextRequest, NextResponse } from "next/server"; import { NextRequest, NextResponse } from 'next/server';
import { prisma, projectService } from "@/lib/prisma"; import { projectService } from '@/lib/prisma';
import { requireSessionAuth } from "@/lib/auth";
import type { Prisma } from "@prisma/client";
type ImportSiteSettings = {
defaultLocale?: unknown;
locales?: unknown;
theme?: unknown;
};
type ImportContentPageTranslation = {
locale?: unknown;
title?: unknown;
slug?: unknown;
content?: unknown;
metaDescription?: unknown;
keywords?: unknown;
};
type ImportContentPage = {
key?: unknown;
status?: unknown;
translations?: unknown;
};
type ImportProject = {
id?: unknown;
slug?: unknown;
defaultLocale?: unknown;
title?: unknown;
description?: unknown;
content?: unknown;
tags?: unknown;
category?: unknown;
featured?: unknown;
github?: unknown;
live?: unknown;
published?: unknown;
imageUrl?: unknown;
difficulty?: unknown;
timeToComplete?: unknown;
technologies?: unknown;
challenges?: unknown;
lessonsLearned?: unknown;
futureImprovements?: unknown;
demoVideo?: unknown;
screenshots?: unknown;
colorScheme?: unknown;
accessibility?: unknown;
performance?: unknown;
analytics?: unknown;
};
type ImportProjectTranslation = {
projectId?: unknown;
locale?: unknown;
title?: unknown;
description?: unknown;
content?: unknown;
metaDescription?: unknown;
keywords?: unknown;
ogImage?: unknown;
schema?: unknown;
};
type ImportPayload = {
projects?: unknown;
siteSettings?: unknown;
contentPages?: unknown;
projectTranslations?: unknown;
};
function asString(v: unknown): string | null {
return typeof v === "string" ? v : null;
}
function asStringArray(v: unknown): string[] | null {
if (!Array.isArray(v)) return null;
const allStrings = v.filter((x) => typeof x === "string") as string[];
return allStrings.length === v.length ? allStrings : null;
}
export async function POST(request: NextRequest) { export async function POST(request: NextRequest) {
try { try {
const isAdminRequest = request.headers.get("x-admin-request") === "true"; const body = await request.json();
if (!isAdminRequest) {
return NextResponse.json({ error: "Admin access required" }, { status: 403 });
}
const authError = requireSessionAuth(request);
if (authError) return authError;
const body = (await request.json()) as ImportPayload;
// Validate import data structure // Validate import data structure
if (!Array.isArray(body.projects)) { if (!body.projects || !Array.isArray(body.projects)) {
return NextResponse.json( return NextResponse.json(
{ error: "Invalid import data format" }, { error: 'Invalid import data format' },
{ status: 400 }, { status: 400 }
); );
} }
const results = { const results = {
imported: 0, imported: 0,
skipped: 0, skipped: 0,
errors: [] as string[], errors: [] as string[]
}; };
// Import SiteSettings (optional)
if (body.siteSettings && typeof body.siteSettings === "object") {
try {
const ss = body.siteSettings as ImportSiteSettings;
const defaultLocale = asString(ss.defaultLocale);
const locales = asStringArray(ss.locales);
const theme = ss.theme as Prisma.InputJsonValue | undefined;
await prisma.siteSettings.upsert({
where: { id: 1 },
create: {
id: 1,
...(defaultLocale ? { defaultLocale } : {}),
...(locales ? { locales } : {}),
...(theme ? { theme } : {}),
},
update: {
...(defaultLocale ? { defaultLocale } : {}),
...(locales ? { locales } : {}),
...(theme ? { theme } : {}),
},
});
} catch {
// non-blocking
}
}
// Import CMS content pages (optional)
if (Array.isArray(body.contentPages)) {
for (const page of body.contentPages) {
try {
const key = asString((page as ImportContentPage)?.key);
if (!key) continue;
const statusRaw = asString((page as ImportContentPage)?.status);
const status = statusRaw === "DRAFT" || statusRaw === "PUBLISHED" ? statusRaw : "PUBLISHED";
const upserted = await prisma.contentPage.upsert({
where: { key },
create: { key, status },
update: { status },
});
const translations = (page as ImportContentPage)?.translations;
if (Array.isArray(translations)) {
for (const tr of translations as ImportContentPageTranslation[]) {
const locale = asString(tr?.locale);
if (!locale || typeof tr?.content === "undefined" || tr?.content === null) continue;
await prisma.contentPageTranslation.upsert({
where: { pageId_locale: { pageId: upserted.id, locale } },
create: {
pageId: upserted.id,
locale,
title: asString(tr.title),
slug: asString(tr.slug),
content: tr.content as Prisma.InputJsonValue,
metaDescription: asString(tr.metaDescription),
keywords: asString(tr.keywords),
},
update: {
title: asString(tr.title),
slug: asString(tr.slug),
content: tr.content as Prisma.InputJsonValue,
metaDescription: asString(tr.metaDescription),
keywords: asString(tr.keywords),
},
});
}
}
} catch (error) {
const key = asString((page as ImportContentPage)?.key) ?? "unknown";
results.errors.push(
`Failed to import content page "${key}": ${error instanceof Error ? error.message : "Unknown error"}`,
);
}
}
}
// Preload existing titles once (avoid O(n^2) DB reads during import)
const existingProjectsResult = await projectService.getAllProjects({ limit: 10000 });
const existingProjects = existingProjectsResult.projects || existingProjectsResult;
const existingTitles = new Set(existingProjects.map(p => p.title));
const existingSlugs = new Set(
existingProjects
.map((p) => (p as unknown as { slug?: string }).slug)
.filter((s): s is string => typeof s === "string" && s.length > 0),
);
// Process each project // Process each project
for (const projectData of body.projects as ImportProject[]) { for (const projectData of body.projects) {
try { try {
// Check if project already exists (by title) // Check if project already exists (by title)
const title = asString(projectData.title); const existingProjectsResult = await projectService.getAllProjects();
if (!title) continue; const existingProjects = existingProjectsResult.projects || existingProjectsResult;
const exists = existingTitles.has(title); const exists = existingProjects.some(p => p.title === projectData.title);
if (exists) { if (exists) {
results.skipped++; results.skipped++;
results.errors.push(`Project "${title}" already exists`); results.errors.push(`Project "${projectData.title}" already exists`);
continue; continue;
} }
// Create new project // Create new project
const created = await projectService.createProject({ await projectService.createProject({
slug: asString(projectData.slug) ?? undefined, title: projectData.title,
defaultLocale: asString(projectData.defaultLocale) ?? "en", description: projectData.description,
title, content: projectData.content,
description: asString(projectData.description) ?? "", tags: projectData.tags || [],
content: projectData.content as Prisma.InputJsonValue | undefined, category: projectData.category,
tags: (asStringArray(projectData.tags) ?? []) as string[], featured: projectData.featured || false,
category: asString(projectData.category) ?? "General", github: projectData.github,
featured: projectData.featured === true, live: projectData.live,
github: asString(projectData.github) ?? undefined,
live: asString(projectData.live) ?? undefined,
published: projectData.published !== false, // Default to true published: projectData.published !== false, // Default to true
imageUrl: asString(projectData.imageUrl) ?? undefined, imageUrl: projectData.imageUrl,
difficulty: asString(projectData.difficulty) ?? "Intermediate", difficulty: projectData.difficulty || 'Intermediate',
timeToComplete: asString(projectData.timeToComplete) ?? undefined, timeToComplete: projectData.timeToComplete,
technologies: (asStringArray(projectData.technologies) ?? []) as string[], technologies: projectData.technologies || [],
challenges: (asStringArray(projectData.challenges) ?? []) as string[], challenges: projectData.challenges || [],
lessonsLearned: (asStringArray(projectData.lessonsLearned) ?? []) as string[], lessonsLearned: projectData.lessonsLearned || [],
futureImprovements: (asStringArray(projectData.futureImprovements) ?? []) as string[], futureImprovements: projectData.futureImprovements || [],
demoVideo: asString(projectData.demoVideo) ?? undefined, demoVideo: projectData.demoVideo,
screenshots: (asStringArray(projectData.screenshots) ?? []) as string[], screenshots: projectData.screenshots || [],
colorScheme: asString(projectData.colorScheme) ?? "Dark", colorScheme: projectData.colorScheme || 'Dark',
accessibility: projectData.accessibility !== false, // Default to true accessibility: projectData.accessibility !== false, // Default to true
performance: (projectData.performance as Record<string, unknown> | null) || { performance: projectData.performance || {
lighthouse: 0, lighthouse: 0,
bundleSize: "0KB", bundleSize: '0KB',
loadTime: "0s", loadTime: '0s'
}, },
analytics: (projectData.analytics as Record<string, unknown> | null) || { analytics: projectData.analytics || {
views: 0, views: 0,
likes: 0, likes: 0,
shares: 0, shares: 0
}, }
}); });
// Import translations (optional, from export v2)
if (Array.isArray(body.projectTranslations)) {
for (const tr of body.projectTranslations as ImportProjectTranslation[]) {
const projectId = typeof tr?.projectId === "number" ? tr.projectId : null;
const locale = asString(tr?.locale);
if (!projectId || !locale) continue;
// Map translation to created project by original slug/title when possible.
// We match by slug if available in exported project list; otherwise by title.
const exportedProject = (body.projects as ImportProject[]).find(
(p) => typeof p.id === "number" && p.id === projectId,
);
const exportedSlug = asString(exportedProject?.slug);
const matches =
(exportedSlug && (created as unknown as { slug?: string }).slug === exportedSlug) ||
(!!asString(exportedProject?.title) &&
(created as unknown as { title?: string }).title === asString(exportedProject?.title));
if (!matches) continue;
const trTitle = asString(tr.title);
const trDescription = asString(tr.description);
if (!trTitle || !trDescription) continue;
await prisma.projectTranslation.upsert({
where: {
projectId_locale: {
projectId: (created as unknown as { id: number }).id,
locale,
},
},
create: {
projectId: (created as unknown as { id: number }).id,
locale,
title: trTitle,
description: trDescription,
content: (tr.content as Prisma.InputJsonValue) ?? null,
metaDescription: asString(tr.metaDescription),
keywords: asString(tr.keywords),
ogImage: asString(tr.ogImage),
schema: (tr.schema as Prisma.InputJsonValue) ?? null,
},
update: {
title: trTitle,
description: trDescription,
content: (tr.content as Prisma.InputJsonValue) ?? null,
metaDescription: asString(tr.metaDescription),
keywords: asString(tr.keywords),
ogImage: asString(tr.ogImage),
schema: (tr.schema as Prisma.InputJsonValue) ?? null,
},
});
}
}
results.imported++; results.imported++;
existingTitles.add(title);
const slug = asString(projectData.slug);
if (slug) existingSlugs.add(slug);
} catch (error) { } catch (error) {
results.skipped++; results.skipped++;
const title = asString(projectData.title) ?? "unknown"; results.errors.push(`Failed to import "${projectData.title}": ${error instanceof Error ? error.message : 'Unknown error'}`);
results.errors.push(
`Failed to import "${title}": ${error instanceof Error ? error.message : "Unknown error"}`,
);
} }
} }
@@ -313,10 +80,10 @@ export async function POST(request: NextRequest) {
results results
}); });
} catch (error) { } catch (error) {
console.error("Import error:", error); console.error('Import error:', error);
return NextResponse.json( return NextResponse.json(
{ error: "Failed to import projects" }, { error: 'Failed to import projects' },
{ status: 500 }, { status: 500 }
); );
} }
} }

View File

@@ -1,25 +1,21 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { prisma } from '@/lib/prisma'; import { prisma } from '@/lib/prisma';
import { apiCache } from '@/lib/cache'; import { apiCache } from '@/lib/cache';
import { requireSessionAuth, checkRateLimit, getRateLimitHeaders, getClientIp } from '@/lib/auth'; import { requireSessionAuth, checkRateLimit, getRateLimitHeaders } from '@/lib/auth';
import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library'; import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library';
import { generateUniqueSlug } from '@/lib/slug';
export async function GET(request: NextRequest) { export async function GET(request: NextRequest) {
try { try {
// Rate limiting // Rate limiting
const ip = getClientIp(request); const ip = request.headers.get('x-forwarded-for') || request.headers.get('x-real-ip') || 'unknown';
const rlKey = ip !== "unknown" ? ip : `dev_unknown:${request.headers.get("user-agent") || "ua"}`; if (!checkRateLimit(ip, 10, 60000)) { // 10 requests per minute
// In development we keep this very high to avoid breaking local navigation/HMR.
const max = process.env.NODE_ENV === "development" ? 300 : 60;
if (!checkRateLimit(rlKey, max, 60000)) {
return new NextResponse( return new NextResponse(
JSON.stringify({ error: 'Rate limit exceeded' }), JSON.stringify({ error: 'Rate limit exceeded' }),
{ {
status: 429, status: 429,
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
...getRateLimitHeaders(rlKey, max, 60000) ...getRateLimitHeaders(ip, 10, 60000)
} }
} }
); );
@@ -34,10 +30,8 @@ export async function GET(request: NextRequest) {
} }
} }
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);
const pageRaw = parseInt(searchParams.get('page') || '1'); const page = parseInt(searchParams.get('page') || '1');
const limitRaw = parseInt(searchParams.get('limit') || '50'); const limit = parseInt(searchParams.get('limit') || '50');
const page = Number.isFinite(pageRaw) && pageRaw > 0 ? pageRaw : 1;
const limit = Number.isFinite(limitRaw) && limitRaw > 0 && limitRaw <= 200 ? limitRaw : 50;
const category = searchParams.get('category'); const category = searchParams.get('category');
const featured = searchParams.get('featured'); const featured = searchParams.get('featured');
const published = searchParams.get('published'); const published = searchParams.get('published');
@@ -151,34 +145,16 @@ export async function POST(request: NextRequest) {
{ status: 403 } { status: 403 }
); );
} }
const authError = requireSessionAuth(request);
if (authError) return authError;
const data = await request.json(); const data = await request.json();
// Remove difficulty field if it exists (since we're removing it) // Remove difficulty field if it exists (since we're removing it)
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
const { difficulty, slug, defaultLocale, ...projectData } = data; const { difficulty, ...projectData } = data;
const derivedSlug =
typeof slug === 'string' && slug.trim()
? slug.trim()
: await generateUniqueSlug({
base: String(projectData.title || 'project'),
isTaken: async (candidate) => {
const existing = await prisma.project.findUnique({
where: { slug: candidate },
select: { id: true },
});
return !!existing;
},
});
const project = await prisma.project.create({ const project = await prisma.project.create({
data: { data: {
...projectData, ...projectData,
slug: derivedSlug,
defaultLocale: typeof defaultLocale === 'string' && defaultLocale ? defaultLocale : undefined,
// Set default difficulty since it's required in schema // Set default difficulty since it's required in schema
difficulty: 'INTERMEDIATE', difficulty: 'INTERMEDIATE',
performance: data.performance || { lighthouse: 0, bundleSize: '0KB', loadTime: '0s' }, performance: data.performance || { lighthouse: 0, bundleSize: '0KB', loadTime: '0s' },

View File

@@ -9,15 +9,28 @@ export async function GET(request: NextRequest) {
const category = searchParams.get('category'); const category = searchParams.get('category');
if (slug) { if (slug) {
const project = await prisma.project.findFirst({ // Search by slug (convert title to slug format)
const projects = await prisma.project.findMany({
where: { where: {
published: true, published: true
slug,
}, },
orderBy: { createdAt: 'desc' }, orderBy: { createdAt: 'desc' }
}); });
return NextResponse.json({ projects: project ? [project] : [] }); // Find exact match by converting titles to slugs
const foundProject = projects.find(project => {
const projectSlug = project.title.toLowerCase()
.replace(/[^a-z0-9]+/g, '-')
.replace(/^-+|-+$/g, '');
return projectSlug === slug;
});
if (foundProject) {
return NextResponse.json({ projects: [foundProject] });
}
// If no exact match, return empty array
return NextResponse.json({ projects: [] });
} }
if (search) { if (search) {

View File

@@ -1,22 +1,164 @@
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import { generateSitemapXml, getSitemapEntries } from "@/lib/sitemap";
interface Project {
slug: string;
updated_at?: string; // Optional timestamp for last modification
}
interface ProjectsData {
posts: Project[];
}
export const dynamic = "force-dynamic"; export const dynamic = "force-dynamic";
export const runtime = "nodejs"; export const runtime = "nodejs"; // Force Node runtime
// Read Ghost API config at runtime, tests may set env vars in beforeAll
// Funktion, um die XML für die Sitemap zu generieren
function generateXml(sitemapRoutes: { url: string; lastModified: string }[]) {
const xmlHeader = '<?xml version="1.0" encoding="UTF-8"?>';
const urlsetOpen =
'<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">';
const urlsetClose = "</urlset>";
const urlEntries = sitemapRoutes
.map(
(route) => `
<url>
<loc>${route.url}</loc>
<lastmod>${route.lastModified}</lastmod>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>`,
)
.join("");
return `${xmlHeader}${urlsetOpen}${urlEntries}${urlsetClose}`;
}
export async function GET() { export async function GET() {
try { const baseUrl = process.env.NEXT_PUBLIC_BASE_URL;
const entries = await getSitemapEntries();
const xml = generateSitemapXml(entries); // Statische Routen
const staticRoutes = [
{
url: `${baseUrl}/`,
lastModified: new Date().toISOString(),
priority: 1,
changeFreq: "weekly",
},
{
url: `${baseUrl}/legal-notice`,
lastModified: new Date().toISOString(),
priority: 0.5,
changeFreq: "yearly",
},
{
url: `${baseUrl}/privacy-policy`,
lastModified: new Date().toISOString(),
priority: 0.5,
changeFreq: "yearly",
},
];
// In test environment we can short-circuit and use a mocked posts payload
if (process.env.NODE_ENV === "test" && process.env.GHOST_MOCK_POSTS) {
const mockData = JSON.parse(process.env.GHOST_MOCK_POSTS);
const projects = (mockData as ProjectsData).posts || [];
const sitemapRoutes = projects.map((project) => {
const lastModified = project.updated_at || new Date().toISOString();
return {
url: `${baseUrl}/projects/${project.slug}`,
lastModified,
priority: 0.8,
changeFreq: "monthly",
};
});
const allRoutes = [...staticRoutes, ...sitemapRoutes];
const xml = generateXml(allRoutes);
// For tests return a plain object so tests can inspect `.body` easily
if (process.env.NODE_ENV === "test") {
return new NextResponse(xml, {
headers: { "Content-Type": "application/xml" },
});
}
return new NextResponse(xml, { return new NextResponse(xml, {
headers: { "Content-Type": "application/xml" }, headers: { "Content-Type": "application/xml" },
}); });
}
try {
// Debug: show whether fetch is present/mocked
// Try global fetch first (tests may mock global.fetch)
let response: Response | undefined;
try {
if (typeof globalThis.fetch === "function") {
response = await globalThis.fetch(
`${process.env.GHOST_API_URL}/ghost/api/content/posts/?key=${process.env.GHOST_API_KEY}&limit=all`,
);
// Debug: inspect the result
console.log("DEBUG sitemap global fetch returned:", response);
}
} catch (_e) {
response = undefined;
}
if (!response || typeof response.ok === "undefined" || !response.ok) {
try {
const mod = await import("node-fetch");
const nodeFetch = mod.default ?? mod;
response = await (nodeFetch as unknown as typeof fetch)(
`${process.env.GHOST_API_URL}/ghost/api/content/posts/?key=${process.env.GHOST_API_KEY}&limit=all`,
);
} catch (err) {
console.log("Failed to fetch posts from Ghost:", err);
return new NextResponse(generateXml(staticRoutes), {
headers: { "Content-Type": "application/xml" },
});
}
}
if (!response || !response.ok) {
console.error(
`Failed to fetch posts: ${response?.statusText ?? "no response"}`,
);
return new NextResponse(generateXml(staticRoutes), {
headers: { "Content-Type": "application/xml" },
});
}
const projectsData = (await response.json()) as ProjectsData;
const projects = projectsData.posts;
// Dynamische Projekt-Routen generieren
const sitemapRoutes = projects.map((project) => {
const lastModified = project.updated_at || new Date().toISOString();
return {
url: `${baseUrl}/projects/${project.slug}`,
lastModified,
priority: 0.8,
changeFreq: "monthly",
};
});
const allRoutes = [...staticRoutes, ...sitemapRoutes];
// Rückgabe der Sitemap im XML-Format
return new NextResponse(generateXml(allRoutes), {
headers: { "Content-Type": "application/xml" },
});
} catch (error) { } catch (error) {
console.error("Failed to generate sitemap:", error); console.log("Failed to fetch posts from Ghost:", error);
// Fail closed: return minimal sitemap // Rückgabe der statischen Routen, falls Fehler auftritt
const xml = generateSitemapXml([]); return new NextResponse(generateXml(staticRoutes), {
return new NextResponse(xml, {
status: 500,
headers: { "Content-Type": "application/xml" }, headers: { "Content-Type": "application/xml" },
}); });
} }

View File

@@ -2,11 +2,6 @@
import { motion, Variants } from "framer-motion"; import { motion, Variants } from "framer-motion";
import { Globe, Server, Wrench, Shield, Gamepad2, Code, Activity, Lightbulb } from "lucide-react"; import { Globe, Server, Wrench, Shield, Gamepad2, Code, Activity, Lightbulb } from "lucide-react";
import { useEffect, useState } from "react";
import { useLocale, useTranslations } from "next-intl";
import type { JSONContent } from "@tiptap/react";
import RichTextClient from "./RichTextClient";
import CurrentlyReading from "./CurrentlyReading";
const staggerContainer: Variants = { const staggerContainer: Variants = {
hidden: { opacity: 0 }, hidden: { opacity: 0 },
@@ -32,58 +27,34 @@ const fadeInUp: Variants = {
}; };
const About = () => { const About = () => {
const locale = useLocale();
const t = useTranslations("home.about");
const [cmsDoc, setCmsDoc] = useState<JSONContent | null>(null);
useEffect(() => {
(async () => {
try {
const res = await fetch(
`/api/content/page?key=${encodeURIComponent("home-about")}&locale=${encodeURIComponent(locale)}`,
);
const data = await res.json();
// Only use CMS content if it exists for the active locale.
if (data?.content?.content && data?.content?.locale === locale) {
setCmsDoc(data.content.content as JSONContent);
} else {
setCmsDoc(null);
}
} catch {
// ignore; fallback to static
setCmsDoc(null);
}
})();
}, [locale]);
const techStack = [ const techStack = [
{ {
category: t("techStack.categories.frontendMobile"), category: "Frontend & Mobile",
icon: Globe, icon: Globe,
items: ["Next.js", "Tailwind CSS", "Flutter"], items: ["Next.js", "Tailwind CSS", "Flutter"],
}, },
{ {
category: t("techStack.categories.backendDevops"), category: "Backend & DevOps",
icon: Server, icon: Server,
items: ["Docker Swarm", "Traefik", "Nginx Proxy Manager", "Redis"], items: ["Docker Swarm", "Traefik", "Nginx Proxy Manager", "Redis"],
}, },
{ {
category: t("techStack.categories.toolsAutomation"), category: "Tools & Automation",
icon: Wrench, icon: Wrench,
items: ["Git", "CI/CD", "n8n", t("techStack.items.selfHostedServices")], items: ["Git", "CI/CD", "n8n", "Self-hosted Services"],
}, },
{ {
category: t("techStack.categories.securityAdmin"), category: "Security & Admin",
icon: Shield, icon: Shield,
items: ["CrowdSec", "Suricata", "Mailcow"], items: ["CrowdSec", "Suricata", "Mailcow"],
}, },
]; ];
const hobbies: Array<{ icon: typeof Code; text: string }> = [ const hobbies: Array<{ icon: typeof Code; text: string }> = [
{ icon: Code, text: t("hobbies.selfHosting") }, { icon: Code, text: "Self-Hosting & DevOps" },
{ icon: Gamepad2, text: t("hobbies.gaming") }, { icon: Gamepad2, text: "Gaming" },
{ icon: Server, text: t("hobbies.gameServers") }, { icon: Server, text: "Setting up Game Servers" },
{ icon: Activity, text: t("hobbies.jogging") }, { icon: Activity, text: "Jogging to clear my mind and stay active" },
]; ];
return ( return (
@@ -105,21 +76,32 @@ const About = () => {
variants={fadeInUp} variants={fadeInUp}
className="text-4xl md:text-5xl font-bold text-stone-900" className="text-4xl md:text-5xl font-bold text-stone-900"
> >
{t("title")} About Me
</motion.h2> </motion.h2>
<motion.div <motion.div
variants={fadeInUp} variants={fadeInUp}
className="prose prose-stone prose-lg text-stone-700 space-y-4" className="prose prose-stone prose-lg text-stone-700 space-y-4"
> >
{cmsDoc ? ( <p>
<RichTextClient doc={cmsDoc} className="prose prose-stone max-w-none" /> Hi, I&apos;m Dennis a student and passionate self-hoster based
) : ( in Osnabrück, Germany.
<> </p>
<p>{t("p1")}</p> <p>
<p>{t("p2")}</p> I love building full-stack web applications with{" "}
<p>{t("p3")}</p> <strong>Next.js</strong> and mobile apps with{" "}
</> <strong>Flutter</strong>. But what really excites me is{" "}
)} <strong>DevOps</strong>: I run my own infrastructure on{" "}
<strong>IONOS</strong> and <strong>OVHcloud</strong>, managing
everything with <strong>Docker Swarm</strong>,{" "}
<strong>Traefik</strong>, and automated CI/CD pipelines with my
own runners.
</p>
<p>
When I&apos;m not coding or tinkering with servers, you&apos;ll
find me <strong>gaming</strong>, <strong>jogging</strong>, or
experimenting with new tech like game servers or automation
workflows with <strong>n8n</strong>.
</p>
<motion.div <motion.div
variants={fadeInUp} variants={fadeInUp}
className="relative overflow-hidden bg-gradient-to-br from-liquid-mint/15 via-liquid-sky/10 to-liquid-lavender/15 border-2 border-liquid-mint/30 rounded-xl p-5 backdrop-blur-sm" className="relative overflow-hidden bg-gradient-to-br from-liquid-mint/15 via-liquid-sky/10 to-liquid-lavender/15 border-2 border-liquid-mint/30 rounded-xl p-5 backdrop-blur-sm"
@@ -128,10 +110,12 @@ const About = () => {
<Lightbulb size={20} className="text-stone-600 flex-shrink-0 mt-0.5" /> <Lightbulb size={20} className="text-stone-600 flex-shrink-0 mt-0.5" />
<div> <div>
<p className="text-sm font-semibold text-stone-800 mb-1"> <p className="text-sm font-semibold text-stone-800 mb-1">
{t("funFactTitle")} Fun Fact
</p> </p>
<p className="text-sm text-stone-700 leading-relaxed"> <p className="text-sm text-stone-700 leading-relaxed">
{t("funFactBody")} Even though I automate a lot, I still use pen and paper
for my calendar and notes it helps me clear my head and
stay focused.
</p> </p>
</div> </div>
</div> </div>
@@ -152,7 +136,7 @@ const About = () => {
variants={fadeInUp} variants={fadeInUp}
className="text-2xl font-bold text-stone-900 mb-6" className="text-2xl font-bold text-stone-900 mb-6"
> >
{t("techStackTitle")} My Tech Stack
</motion.h3> </motion.h3>
<div className="grid grid-cols-1 gap-4"> <div className="grid grid-cols-1 gap-4">
{techStack.map((stack, idx) => ( {techStack.map((stack, idx) => (
@@ -163,7 +147,7 @@ const About = () => {
scale: 1.02, scale: 1.02,
transition: { duration: 0.4, ease: "easeOut" }, transition: { duration: 0.4, ease: "easeOut" },
}} }}
className={`p-5 rounded-xl border-2 transition-[background-color,border-color,box-shadow] duration-500 ease-out ${ className={`p-5 rounded-xl border-2 transition-all duration-500 ease-out ${
idx === 0 idx === 0
? "bg-gradient-to-br from-liquid-sky/10 to-liquid-mint/10 border-liquid-sky/30 hover:border-liquid-sky/50 hover:from-liquid-sky/15 hover:to-liquid-mint/15" ? "bg-gradient-to-br from-liquid-sky/10 to-liquid-mint/10 border-liquid-sky/30 hover:border-liquid-sky/50 hover:from-liquid-sky/15 hover:to-liquid-mint/15"
: idx === 1 : idx === 1
@@ -210,7 +194,7 @@ const About = () => {
variants={fadeInUp} variants={fadeInUp}
className="text-xl font-bold text-stone-900 mb-4" className="text-xl font-bold text-stone-900 mb-4"
> >
{t("hobbiesTitle")} When I&apos;m Not Coding
</motion.h3> </motion.h3>
<div className="space-y-3"> <div className="space-y-3">
{hobbies.map((hobby, idx) => ( {hobbies.map((hobby, idx) => (
@@ -222,7 +206,7 @@ const About = () => {
scale: 1.02, scale: 1.02,
transition: { duration: 0.4, ease: "easeOut" }, transition: { duration: 0.4, ease: "easeOut" },
}} }}
className={`flex items-center gap-3 p-4 rounded-xl border-2 transition-[background-color,border-color,box-shadow] duration-500 ease-out ${ className={`flex items-center gap-3 p-4 rounded-xl border-2 transition-all duration-500 ease-out ${
idx === 0 idx === 0
? "bg-gradient-to-r from-liquid-mint/10 to-liquid-sky/10 border-liquid-mint/30 hover:border-liquid-mint/50 hover:from-liquid-mint/15 hover:to-liquid-sky/15" ? "bg-gradient-to-r from-liquid-mint/10 to-liquid-sky/10 border-liquid-mint/30 hover:border-liquid-mint/50 hover:from-liquid-mint/15 hover:to-liquid-sky/15"
: idx === 1 : idx === 1
@@ -240,14 +224,6 @@ const About = () => {
))} ))}
</div> </div>
</div> </div>
{/* Currently Reading */}
<motion.div
variants={fadeInUp}
className="mt-8"
>
<CurrentlyReading />
</motion.div>
</motion.div> </motion.div>
</div> </div>
</div> </div>

View File

@@ -50,32 +50,32 @@ interface StatusData {
} }
export default function ActivityFeed() { export default function ActivityFeed() {
const [mounted, setMounted] = useState(false);
const [data, setData] = useState<StatusData | null>(null); const [data, setData] = useState<StatusData | null>(null);
const [isExpanded, setIsExpanded] = useState(true); const [isExpanded, setIsExpanded] = useState(true);
const [isMinimized, setIsMinimized] = useState(false); const [isMinimized, setIsMinimized] = useState(false);
const [hasActivity, setHasActivity] = useState(false); const [hasActivity, setHasActivity] = useState(false);
// NOTE: Don't read localStorage during initial render. // Initialize with default value to prevent hydration mismatch
// Doing so can cause a hydration mismatch (SSR default vs client preference),
// which can leave the feed stuck in its initial (small/transparent) motion styles.
const [isTrackingEnabled, setIsTrackingEnabled] = useState(true); const [isTrackingEnabled, setIsTrackingEnabled] = useState(true);
const [quote, setQuote] = useState<{ const [quote, setQuote] = useState<{
content: string; content: string;
author: string; author: string;
} | null>(null); } | null>(null);
// Sync tracking preference after mount (client-only) // Load tracking preference from localStorage after mount to prevent hydration mismatch
useEffect(() => { useEffect(() => {
if (typeof window === "undefined") return; setMounted(true);
try { if (typeof window !== "undefined") {
const stored = localStorage.getItem("activityTrackingEnabled"); try {
const enabled = stored !== "false"; // Default to true if not set const stored = localStorage.getItem("activityTrackingEnabled");
setIsTrackingEnabled(enabled); setIsTrackingEnabled(stored !== "false"); // Default to true if not set
} catch (error) { } catch (error) {
// localStorage might be disabled // localStorage might be disabled
if (process.env.NODE_ENV === "development") { if (process.env.NODE_ENV === 'development') {
console.warn("Failed to read tracking preference:", error); console.warn('Failed to read tracking preference:', error);
}
setIsTrackingEnabled(true); // Default to enabled
} }
// Keep default (enabled)
} }
}, []); }, []);
@@ -88,17 +88,8 @@ export default function ActivityFeed() {
const fetchData = async () => { const fetchData = async () => {
try { try {
const fallback: StatusData = {
status: { text: "offline", color: "gray" },
music: null,
gaming: null,
coding: null,
};
// Check if fetch is available (should be, but safety check) // Check if fetch is available (should be, but safety check)
if (typeof fetch === 'undefined') { if (typeof fetch === 'undefined') {
setData(fallback);
setHasActivity(false);
return; return;
} }
@@ -117,9 +108,6 @@ export default function ActivityFeed() {
if (process.env.NODE_ENV === 'development' && res) { if (process.env.NODE_ENV === 'development' && res) {
console.warn('ActivityFeed: API returned non-OK status:', res.status); console.warn('ActivityFeed: API returned non-OK status:', res.status);
} }
// Don't stay in tiny "loading" state forever; show stable fallback UI.
setData(fallback);
setHasActivity(false);
return; return;
} }
@@ -130,8 +118,6 @@ export default function ActivityFeed() {
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
console.warn('ActivityFeed: Failed to parse JSON response:', parseError); console.warn('ActivityFeed: Failed to parse JSON response:', parseError);
} }
setData(fallback);
setHasActivity(false);
return; return;
} }
@@ -149,8 +135,6 @@ export default function ActivityFeed() {
} }
if (!json || typeof json !== 'object') { if (!json || typeof json !== 'object') {
setData(fallback);
setHasActivity(false);
return; return;
} }
@@ -188,14 +172,7 @@ export default function ActivityFeed() {
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
console.error("Failed to fetch activity:", error); console.error("Failed to fetch activity:", error);
} }
// Don't set error state - show stable fallback // Don't set error state - just fail silently
setData({
status: { text: "offline", color: "gray" },
music: null,
gaming: null,
coding: null,
});
setHasActivity(false);
} }
}; };
@@ -1483,63 +1460,29 @@ export default function ActivityFeed() {
} }
}; };
// Don't render until mounted to prevent hydration mismatch
if (!mounted) return null;
// Don't render if tracking is disabled and no data // Don't render if tracking is disabled and no data
if (!isTrackingEnabled && !data) { if (!isTrackingEnabled && !data) return null;
return (
<div className="fixed bottom-4 right-4 md:bottom-6 md:right-6 z-40 font-sans w-[280px] sm:w-[320px] max-w-[calc(100vw-2rem)] pointer-events-none">
<motion.div
initial={false}
animate={{ scale: 1, opacity: 1 }}
className="pointer-events-auto bg-black/95 backdrop-blur-2xl border border-white/10 rounded-2xl shadow-2xl overflow-hidden w-full"
>
<div className="px-4 py-3 flex items-center justify-between">
<div className="flex items-center gap-3">
<Activity size={18} className="text-white" />
<div className="text-left">
<h3 className="text-sm font-bold text-white">Live Activity</h3>
<p className="text-[10px] text-white/50">Tracking disabled</p>
</div>
</div>
<button
type="button"
onClick={toggleTracking}
className="text-xs font-semibold px-3 py-1.5 rounded-full bg-white/10 text-white hover:bg-white/15 transition-colors border border-white/10"
title="Enable activity tracking"
>
Enable
</button>
</div>
</motion.div>
</div>
);
}
// If tracking disabled but we have data, show a disabled state // If tracking disabled but we have data, show a disabled state
if (!isTrackingEnabled && data) { if (!isTrackingEnabled && data) {
return ( return (
<div className="fixed bottom-4 right-4 md:bottom-6 md:right-6 z-40 font-sans w-[280px] sm:w-[320px] max-w-[calc(100vw-2rem)] pointer-events-none"> <div className="fixed bottom-4 right-4 md:bottom-6 md:right-6 z-40 pointer-events-auto">
<motion.div <motion.div
initial={false} initial={{ scale: 0, opacity: 0 }}
animate={{ scale: 1, opacity: 1 }} animate={{ scale: 1, opacity: 1 }}
className="pointer-events-auto bg-black/95 backdrop-blur-2xl border border-white/10 rounded-2xl shadow-2xl overflow-hidden w-full" className="bg-black/80 backdrop-blur-xl border border-white/10 rounded-xl p-3 shadow-2xl"
> >
<div className="px-4 py-3 flex items-center justify-between"> <button
<div className="flex items-center gap-3"> onClick={toggleTracking}
<Activity size={18} className="text-white" /> className="flex items-center gap-2 text-white/60 hover:text-white transition-colors"
<div className="text-left"> title="Activity tracking is disabled. Click to enable."
<h3 className="text-sm font-bold text-white">Live Activity</h3> >
<p className="text-[10px] text-white/50">Tracking disabled</p> <Activity size={16} />
</div> <span className="text-xs">Tracking disabled</span>
</div> </button>
<button
type="button"
onClick={toggleTracking}
className="text-xs font-semibold px-3 py-1.5 rounded-full bg-white/10 text-white hover:bg-white/15 transition-colors border border-white/10"
title="Enable activity tracking"
>
Enable
</button>
</div>
</motion.div> </motion.div>
</div> </div>
); );
@@ -1551,9 +1494,9 @@ export default function ActivityFeed() {
return ( return (
<div className="fixed bottom-4 right-4 md:bottom-6 md:right-6 flex flex-col items-end gap-3 z-40 font-sans pointer-events-none w-[280px] sm:w-[320px] max-w-[calc(100vw-2rem)]"> <div className="fixed bottom-4 right-4 md:bottom-6 md:right-6 flex flex-col items-end gap-3 z-40 font-sans pointer-events-none w-[280px] sm:w-[320px] max-w-[calc(100vw-2rem)]">
<motion.div <motion.div
initial={false} initial={{ scale: 0, opacity: 0 }}
animate={{ scale: 1, opacity: 1 }} animate={{ scale: 1, opacity: 1 }}
className="pointer-events-auto bg-black/95 backdrop-blur-2xl border border-white/10 rounded-2xl shadow-2xl overflow-hidden w-full" className="pointer-events-auto bg-black/90 backdrop-blur-2xl border border-white/10 rounded-2xl shadow-2xl overflow-hidden w-full"
> >
<div className="w-full px-4 py-3 flex items-center justify-between"> <div className="w-full px-4 py-3 flex items-center justify-between">
<div className="flex items-center gap-3"> <div className="flex items-center gap-3">
@@ -1584,14 +1527,14 @@ export default function ActivityFeed() {
if (isMinimized) { if (isMinimized) {
return ( return (
<motion.button <motion.button
initial={false} initial={{ scale: 0 }}
animate={{ scale: 1 }} animate={{ scale: 1 }}
onClick={() => setIsMinimized(false)} onClick={() => setIsMinimized(false)}
className="fixed bottom-4 right-4 md:bottom-6 md:right-6 z-40 pointer-events-auto bg-white/80 backdrop-blur-xl border border-white/60 p-3 rounded-full shadow-xl hover:scale-110 transition-transform" className="fixed bottom-4 right-4 md:bottom-6 md:right-6 z-40 pointer-events-auto bg-black/80 backdrop-blur-xl border border-white/10 p-3 rounded-full shadow-2xl hover:scale-110 transition-transform"
> >
<Activity size={20} className="text-stone-900" /> <Activity size={20} className="text-white" />
{activeCount > 0 && ( {activeCount > 0 && (
<span className="absolute -top-1 -right-1 bg-stone-900 text-white text-[10px] font-bold rounded-full w-5 h-5 flex items-center justify-center"> <span className="absolute -top-1 -right-1 bg-green-500 text-white text-[10px] font-bold rounded-full w-5 h-5 flex items-center justify-center">
{activeCount} {activeCount}
</span> </span>
)} )}
@@ -1604,7 +1547,7 @@ export default function ActivityFeed() {
{/* Main Container */} {/* Main Container */}
<motion.div <motion.div
layout layout
className="pointer-events-auto bg-black/95 backdrop-blur-2xl border border-white/10 rounded-2xl shadow-2xl w-full overflow-hidden [&_a]:text-inherit [&_a]:no-underline" className="pointer-events-auto bg-black/90 backdrop-blur-2xl border border-white/10 rounded-2xl shadow-2xl w-full overflow-hidden [&_a]:text-inherit [&_a]:no-underline"
> >
{/* Header - Always Visible - Changed from button to div to fix nesting error */} {/* Header - Always Visible - Changed from button to div to fix nesting error */}
<div <div

View File

@@ -292,11 +292,11 @@ export default function ChatWidget() {
setIsOpen(true); setIsOpen(true);
} }
}} }}
className="fixed bottom-4 left-4 md:bottom-6 md:left-6 z-30 bg-white/80 backdrop-blur-xl text-stone-900 p-3.5 rounded-full shadow-[0_10px_26px_rgba(41,37,36,0.16)] hover:bg-white hover:scale-105 transition-all duration-300 group cursor-pointer border border-white/60 ring-1 ring-white/30" className="fixed bottom-4 left-4 md:bottom-6 md:left-6 z-30 bg-[#292524] text-[#fdfcf8] p-3.5 rounded-full shadow-[0_8px_20px_rgba(41,37,36,0.25)] hover:bg-[#44403c] hover:scale-105 transition-all duration-300 group cursor-pointer border border-[#f3f1e7]/20 ring-1 ring-[#f3f1e7]/10"
aria-label="Open chat" aria-label="Open chat"
> >
<MessageCircle size={24} /> <MessageCircle size={24} />
<span className="absolute top-0 right-0 w-3 h-3 bg-green-500 rounded-full animate-pulse shadow-sm border-2 border-white" /> <span className="absolute top-0 right-0 w-3 h-3 bg-green-500 rounded-full animate-pulse shadow-sm border-2 border-[#292524]" />
{/* Tooltip */} {/* Tooltip */}
<span className="absolute bottom-full left-1/2 -translate-x-1/2 mb-3 px-3 py-1.5 bg-stone-900/90 text-stone-50 text-xs font-medium rounded-lg opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap pointer-events-none z-[100] shadow-xl backdrop-blur-sm"> <span className="absolute bottom-full left-1/2 -translate-x-1/2 mb-3 px-3 py-1.5 bg-stone-900/90 text-stone-50 text-xs font-medium rounded-lg opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap pointer-events-none z-[100] shadow-xl backdrop-blur-sm">
@@ -315,16 +315,16 @@ export default function ChatWidget() {
animate={{ opacity: 1, y: 0, scale: 1, filter: "blur(0px)" }} animate={{ opacity: 1, y: 0, scale: 1, filter: "blur(0px)" }}
exit={{ opacity: 0, y: 20, scale: 0.95, filter: "blur(10px)" }} exit={{ opacity: 0, y: 20, scale: 0.95, filter: "blur(10px)" }}
transition={{ type: "spring", damping: 30, stiffness: 400 }} transition={{ type: "spring", damping: 30, stiffness: 400 }}
className="fixed bottom-20 left-4 right-4 md:bottom-24 md:left-6 md:right-auto z-30 md:w-[380px] h-[60vh] md:h-[550px] max-h-[600px] bg-white/80 backdrop-blur-xl saturate-100 rounded-2xl shadow-[0_12px_40px_rgba(41,37,36,0.16)] flex flex-col overflow-hidden border border-white/60 ring-1 ring-white/30" className="fixed bottom-20 left-4 right-4 md:bottom-24 md:left-6 md:right-auto z-30 md:w-[380px] h-[60vh] md:h-[550px] max-h-[600px] bg-[#fdfcf8]/95 backdrop-blur-xl saturate-100 rounded-2xl shadow-[0_12px_40px_rgba(41,37,36,0.2)] flex flex-col overflow-hidden border border-[#e7e5e4] ring-1 ring-[#f3f1e7]"
> >
{/* Header */} {/* Header */}
<div className="bg-white/70 text-stone-900 p-4 flex items-center justify-between border-b border-white/50"> <div className="bg-[#fdfcf8] text-[#292524] p-4 flex items-center justify-between border-b border-[#e7e5e4]">
<div className="flex items-center gap-3"> <div className="flex items-center gap-3">
<div className="relative"> <div className="relative">
<div className="w-10 h-10 rounded-full bg-gradient-to-br from-liquid-mint/50 via-liquid-lavender/40 to-liquid-rose/40 flex items-center justify-center ring-1 ring-white/50 shadow-sm"> <div className="w-10 h-10 rounded-full bg-gradient-to-br from-[#f3f1e7] to-[#fdfcf8] flex items-center justify-center ring-1 ring-[#e7e5e4] shadow-sm">
<Sparkles size={18} className="text-stone-800" /> <Sparkles size={18} className="text-[#57534e]" />
</div> </div>
<span className="absolute bottom-0 right-0 w-2.5 h-2.5 bg-green-500 rounded-full border-2 border-white shadow-sm" /> <span className="absolute bottom-0 right-0 w-2.5 h-2.5 bg-green-500 rounded-full border-2 border-[#fdfcf8] shadow-sm" />
</div> </div>
<div className="min-w-0 flex-1"> <div className="min-w-0 flex-1">
<h3 className="font-bold text-sm truncate text-stone-900 tracking-tight"> <h3 className="font-bold text-sm truncate text-stone-900 tracking-tight">
@@ -366,12 +366,12 @@ export default function ChatWidget() {
<div <div
className={`max-w-[85%] rounded-2xl px-4 py-3 shadow-sm ${ className={`max-w-[85%] rounded-2xl px-4 py-3 shadow-sm ${
message.sender === "user" message.sender === "user"
? "bg-stone-900 text-white" ? "bg-[#292524] text-[#fdfcf8]"
: "bg-white/70 text-stone-900 border border-white/60" : "bg-[#f3f1e7] text-[#292524] border border-[#e7e5e4]"
}`} }`}
> >
<p className={`text-sm whitespace-pre-wrap break-words leading-relaxed ${ <p className={`text-sm whitespace-pre-wrap break-words leading-relaxed ${
message.sender === "user" ? "text-white/90 font-normal" : "text-stone-900 font-medium" message.sender === "user" ? "text-[#fdfcf8]/90 font-light" : "text-[#292524] font-medium"
}`}> }`}>
{message.text} {message.text}
</p> </p>

View File

@@ -6,7 +6,6 @@ import dynamic from "next/dynamic";
import { ToastProvider } from "@/components/Toast"; import { ToastProvider } from "@/components/Toast";
import ErrorBoundary from "@/components/ErrorBoundary"; import ErrorBoundary from "@/components/ErrorBoundary";
import { AnalyticsProvider } from "@/components/AnalyticsProvider"; import { AnalyticsProvider } from "@/components/AnalyticsProvider";
import { ConsentProvider, useConsent } from "./ConsentProvider";
// Dynamic import with SSR disabled to avoid framer-motion issues // Dynamic import with SSR disabled to avoid framer-motion issues
const BackgroundBlobs = dynamic(() => import("@/components/BackgroundBlobs").catch(() => ({ default: () => null })), { const BackgroundBlobs = dynamic(() => import("@/components/BackgroundBlobs").catch(() => ({ default: () => null })), {
@@ -71,43 +70,16 @@ export default function ClientProviders({
return ( return (
<ErrorBoundary> <ErrorBoundary>
<ErrorBoundary> <ErrorBoundary>
<ConsentProvider> <AnalyticsProvider>
<GatedProviders mounted={mounted} is404Page={is404Page}> <ErrorBoundary>
{children} <ToastProvider>
</GatedProviders> {mounted && <BackgroundBlobs />}
</ConsentProvider> <div className="relative z-10">{children}</div>
{mounted && !is404Page && <ChatWidget />}
</ToastProvider>
</ErrorBoundary>
</AnalyticsProvider>
</ErrorBoundary> </ErrorBoundary>
</ErrorBoundary> </ErrorBoundary>
); );
} }
function GatedProviders({
children,
mounted,
is404Page,
}: {
children: React.ReactNode;
mounted: boolean;
is404Page: boolean;
}) {
const { consent } = useConsent();
const pathname = usePathname();
const isAdminRoute = pathname.startsWith("/manage") || pathname.startsWith("/editor");
// If consent is not decided yet, treat optional features as off
const analyticsEnabled = !!consent?.analytics;
const chatEnabled = !!consent?.chat;
const content = (
<ErrorBoundary>
<ToastProvider>
{mounted && <BackgroundBlobs />}
<div className="relative z-10">{children}</div>
{mounted && !is404Page && !isAdminRoute && chatEnabled && <ChatWidget />}
</ToastProvider>
</ErrorBoundary>
);
return analyticsEnabled ? <AnalyticsProvider>{content}</AnalyticsProvider> : content;
}

View File

@@ -1,116 +0,0 @@
"use client";
import React, { useState } from "react";
import { useConsent, type ConsentState } from "./ConsentProvider";
import { useTranslations } from "next-intl";
export default function ConsentBanner() {
const { consent, ready, setConsent } = useConsent();
const [draft, setDraft] = useState<ConsentState>({ analytics: false, chat: false });
const [minimized, setMinimized] = useState(false);
const t = useTranslations("consent");
// Avoid hydration mismatch + avoid "flash then disappear":
// Only decide whether to show the banner after consent has been read client-side.
const shouldShow = ready && consent === null;
if (!shouldShow) return null;
const s = {
title: t("title"),
description: t("description"),
essential: t("essential"),
analytics: t("analytics"),
chat: t("chat"),
alwaysOn: t("alwaysOn"),
acceptAll: t("acceptAll"),
acceptSelected: t("acceptSelected"),
rejectAll: t("rejectAll"),
hide: t("hide"),
};
if (minimized) {
return (
<div className="fixed bottom-4 right-4 z-[60]">
<button
type="button"
onClick={() => setMinimized(false)}
className="px-4 py-2 rounded-full bg-white/80 backdrop-blur-xl border border-white/60 shadow-lg text-stone-800 font-semibold hover:bg-white transition-colors"
aria-label="Open privacy settings"
>
{s.title}
</button>
</div>
);
}
return (
<div className="fixed bottom-4 right-4 z-[60] max-w-[calc(100vw-2rem)]">
<div className="w-[360px] max-w-full bg-white/85 backdrop-blur-xl border border-white/60 rounded-2xl shadow-[0_12px_40px_rgba(41,37,36,0.14)] p-4">
<div className="flex items-start justify-between gap-3">
<div className="min-w-0">
<div className="text-base font-bold text-stone-900">{s.title}</div>
<p className="text-xs text-stone-600 mt-1 leading-snug">{s.description}</p>
</div>
<button
type="button"
onClick={() => setMinimized(true)}
className="shrink-0 text-xs text-stone-500 hover:text-stone-900 transition-colors"
aria-label="Minimize privacy banner"
title="Minimize"
>
{s.hide}
</button>
</div>
<div className="mt-3 space-y-2">
<div className="flex items-center justify-between gap-3">
<div className="text-xs font-semibold text-stone-800">{s.essential}</div>
<div className="text-[11px] text-stone-500">{s.alwaysOn}</div>
</div>
<label className="flex items-center justify-between gap-3 py-1">
<span className="text-sm font-semibold text-stone-800">{s.analytics}</span>
<input
type="checkbox"
checked={draft.analytics}
onChange={(e) => setDraft((p) => ({ ...p, analytics: e.target.checked }))}
className="w-4 h-4 accent-stone-900"
/>
</label>
<label className="flex items-center justify-between gap-3 py-1">
<span className="text-sm font-semibold text-stone-800">{s.chat}</span>
<input
type="checkbox"
checked={draft.chat}
onChange={(e) => setDraft((p) => ({ ...p, chat: e.target.checked }))}
className="w-4 h-4 accent-stone-900"
/>
</label>
</div>
<div className="mt-3 flex flex-col gap-2">
<button
onClick={() => setConsent({ analytics: true, chat: true })}
className="px-4 py-2 rounded-xl bg-stone-900 text-stone-50 font-semibold hover:bg-stone-800 transition-colors"
>
{s.acceptAll}
</button>
<button
onClick={() => setConsent(draft)}
className="px-4 py-2 rounded-xl bg-white border border-stone-200 text-stone-800 font-semibold hover:bg-stone-50 transition-colors"
>
{s.acceptSelected}
</button>
<button
onClick={() => setConsent({ analytics: false, chat: false })}
className="px-4 py-2 rounded-xl bg-transparent text-stone-600 font-semibold hover:text-stone-900 transition-colors"
>
{s.rejectAll}
</button>
</div>
</div>
</div>
);
}

View File

@@ -1,87 +0,0 @@
"use client";
import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
export type ConsentState = {
analytics: boolean;
chat: boolean;
};
const COOKIE_NAME = "dk0_consent_v1";
function readConsentFromCookie(): ConsentState | null {
if (typeof document === "undefined") return null;
const match = document.cookie
.split(";")
.map((c) => c.trim())
.find((c) => c.startsWith(`${COOKIE_NAME}=`));
if (!match) return null;
const value = decodeURIComponent(match.split("=").slice(1).join("="));
try {
const parsed = JSON.parse(value) as Partial<ConsentState>;
return {
analytics: !!parsed.analytics,
chat: !!parsed.chat,
};
} catch {
return null;
}
}
function writeConsentCookie(value: ConsentState) {
const encoded = encodeURIComponent(JSON.stringify(value));
// 180 days
const maxAge = 60 * 60 * 24 * 180;
document.cookie = `${COOKIE_NAME}=${encoded}; path=/; max-age=${maxAge}; samesite=lax`;
}
const ConsentContext = createContext<{
consent: ConsentState | null;
ready: boolean;
setConsent: (next: ConsentState) => void;
resetConsent: () => void;
}>({
consent: null,
ready: false,
setConsent: () => {},
resetConsent: () => {},
});
export function ConsentProvider({ children }: { children: React.ReactNode }) {
// IMPORTANT:
// Don't read `document.cookie` during SSR render (document is undefined), otherwise the
// server will render the banner while the client immediately hides it -> hydration mismatch.
// We resolve consent on the client after mount and only render the banner once `ready=true`.
const [consent, setConsentState] = useState<ConsentState | null>(null);
const [ready, setReady] = useState(false);
useEffect(() => {
setConsentState(readConsentFromCookie());
setReady(true);
}, []);
const setConsent = useCallback((next: ConsentState) => {
setConsentState(next);
writeConsentCookie(next);
}, []);
const resetConsent = useCallback(() => {
setConsentState(null);
// expire cookie
document.cookie = `${COOKIE_NAME}=; path=/; max-age=0; samesite=lax`;
}, []);
const value = useMemo(
() => ({ consent, ready, setConsent, resetConsent }),
[consent, ready, setConsent, resetConsent],
);
return <ConsentContext.Provider value={value}>{children}</ConsentContext.Provider>;
}
export function useConsent() {
return useContext(ConsentContext);
}
export const consentCookieName = COOKIE_NAME;

View File

@@ -4,37 +4,14 @@ import { useState, useEffect } from "react";
import { motion } from "framer-motion"; import { motion } from "framer-motion";
import { Mail, MapPin, Send } from "lucide-react"; import { Mail, MapPin, Send } from "lucide-react";
import { useToast } from "@/components/Toast"; import { useToast } from "@/components/Toast";
import { useLocale, useTranslations } from "next-intl";
import type { JSONContent } from "@tiptap/react";
import RichTextClient from "./RichTextClient";
const Contact = () => { const Contact = () => {
const [mounted, setMounted] = useState(false);
const { showEmailSent, showEmailError } = useToast(); const { showEmailSent, showEmailError } = useToast();
const locale = useLocale();
const t = useTranslations("home.contact");
const tForm = useTranslations("home.contact.form");
const tInfo = useTranslations("home.contact.info");
const [cmsDoc, setCmsDoc] = useState<JSONContent | null>(null);
useEffect(() => { useEffect(() => {
(async () => { setMounted(true);
try { }, []);
const res = await fetch(
`/api/content/page?key=${encodeURIComponent("home-contact")}&locale=${encodeURIComponent(locale)}`,
);
const data = await res.json();
// Only use CMS content if it exists for the active locale.
if (data?.content?.content && data?.content?.locale === locale) {
setCmsDoc(data.content.content as JSONContent);
} else {
setCmsDoc(null);
}
} catch {
// ignore; fallback to static
setCmsDoc(null);
}
})();
}, [locale]);
const [formData, setFormData] = useState({ const [formData, setFormData] = useState({
name: "", name: "",
@@ -51,27 +28,27 @@ const Contact = () => {
const newErrors: Record<string, string> = {}; const newErrors: Record<string, string> = {};
if (!formData.name.trim()) { if (!formData.name.trim()) {
newErrors.name = tForm("errors.nameRequired"); newErrors.name = "Name is required";
} else if (formData.name.trim().length < 2) { } else if (formData.name.trim().length < 2) {
newErrors.name = tForm("errors.nameMin"); newErrors.name = "Name must be at least 2 characters";
} }
if (!formData.email.trim()) { if (!formData.email.trim()) {
newErrors.email = tForm("errors.emailRequired"); newErrors.email = "Email is required";
} else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(formData.email)) { } else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(formData.email)) {
newErrors.email = tForm("errors.emailInvalid"); newErrors.email = "Please enter a valid email address";
} }
if (!formData.subject.trim()) { if (!formData.subject.trim()) {
newErrors.subject = tForm("errors.subjectRequired"); newErrors.subject = "Subject is required";
} else if (formData.subject.trim().length < 3) { } else if (formData.subject.trim().length < 3) {
newErrors.subject = tForm("errors.subjectMin"); newErrors.subject = "Subject must be at least 3 characters";
} }
if (!formData.message.trim()) { if (!formData.message.trim()) {
newErrors.message = tForm("errors.messageRequired"); newErrors.message = "Message is required";
} else if (formData.message.trim().length < 10) { } else if (formData.message.trim().length < 10) {
newErrors.message = tForm("errors.messageMin"); newErrors.message = "Message must be at least 10 characters";
} }
setErrors(newErrors); setErrors(newErrors);
@@ -155,17 +132,21 @@ const Contact = () => {
const contactInfo = [ const contactInfo = [
{ {
icon: Mail, icon: Mail,
title: tInfo("email"), title: "Email",
value: "contact@dk0.dev", value: "contact@dk0.dev",
href: "mailto:contact@dk0.dev", href: "mailto:contact@dk0.dev",
}, },
{ {
icon: MapPin, icon: MapPin,
title: tInfo("location"), title: "Location",
value: tInfo("locationValue"), value: "Osnabrück, Germany",
}, },
]; ];
if (!mounted) {
return null;
}
return ( return (
<section <section
id="contact" id="contact"
@@ -181,15 +162,12 @@ const Contact = () => {
className="text-center mb-16" className="text-center mb-16"
> >
<h2 className="text-4xl md:text-5xl font-bold mb-6 text-stone-900"> <h2 className="text-4xl md:text-5xl font-bold mb-6 text-stone-900">
{t("title")} Contact Me
</h2> </h2>
{cmsDoc ? ( <p className="text-xl text-stone-700 max-w-2xl mx-auto mt-4">
<RichTextClient doc={cmsDoc} className="prose prose-stone max-w-2xl mx-auto mt-4 text-stone-700" /> Interested in working together or have questions about my projects?
) : ( Feel free to reach out!
<p className="text-xl text-stone-700 max-w-2xl mx-auto mt-4"> </p>
{t("subtitle")}
</p>
)}
</motion.div> </motion.div>
<div className="grid grid-cols-1 lg:grid-cols-2 gap-12"> <div className="grid grid-cols-1 lg:grid-cols-2 gap-12">
@@ -203,10 +181,12 @@ const Contact = () => {
> >
<div> <div>
<h3 className="text-2xl font-bold text-stone-900 mb-6"> <h3 className="text-2xl font-bold text-stone-900 mb-6">
{t("getInTouch")} Get In Touch
</h3> </h3>
<p className="text-stone-700 leading-relaxed"> <p className="text-stone-700 leading-relaxed">
{t("getInTouchBody")} I&apos;m always available to discuss new opportunities,
interesting projects, or simply chat about technology and
innovation.
</p> </p>
</div> </div>
@@ -228,7 +208,7 @@ const Contact = () => {
x: 8, x: 8,
transition: { duration: 0.4, ease: "easeOut" }, transition: { duration: 0.4, ease: "easeOut" },
}} }}
className="flex items-center space-x-4 p-4 rounded-2xl glass-card hover:bg-white/80 transition-[background-color,border-color,box-shadow] duration-500 ease-out group border-transparent hover:border-white/70" className="flex items-center space-x-4 p-4 rounded-2xl glass-card hover:bg-white/80 transition-all duration-500 ease-out group border-transparent hover:border-white/70"
> >
<div className="p-3 bg-white rounded-xl shadow-sm group-hover:shadow-md transition-all"> <div className="p-3 bg-white rounded-xl shadow-sm group-hover:shadow-md transition-all">
<info.icon className="w-6 h-6 text-stone-700" /> <info.icon className="w-6 h-6 text-stone-700" />
@@ -253,7 +233,7 @@ const Contact = () => {
className="glass-card p-8 rounded-3xl bg-white/50 border border-white/70" className="glass-card p-8 rounded-3xl bg-white/50 border border-white/70"
> >
<h3 className="text-2xl font-bold text-gray-800 mb-6"> <h3 className="text-2xl font-bold text-gray-800 mb-6">
{tForm("title")} Send Message
</h3> </h3>
<form onSubmit={handleSubmit} className="space-y-6"> <form onSubmit={handleSubmit} className="space-y-6">
@@ -278,7 +258,7 @@ const Contact = () => {
? "border-red-400 focus:ring-red-400" ? "border-red-400 focus:ring-red-400"
: "border-white/60 focus:ring-liquid-blue focus:border-transparent" : "border-white/60 focus:ring-liquid-blue focus:border-transparent"
}`} }`}
placeholder={tForm("placeholders.name")} placeholder="Your name"
aria-invalid={ aria-invalid={
errors.name && touched.name ? "true" : "false" errors.name && touched.name ? "true" : "false"
} }
@@ -313,7 +293,7 @@ const Contact = () => {
? "border-red-400 focus:ring-red-400" ? "border-red-400 focus:ring-red-400"
: "border-white/60 focus:ring-liquid-blue focus:border-transparent" : "border-white/60 focus:ring-liquid-blue focus:border-transparent"
}`} }`}
placeholder={tForm("placeholders.email")} placeholder="your@email.com"
aria-invalid={ aria-invalid={
errors.email && touched.email ? "true" : "false" errors.email && touched.email ? "true" : "false"
} }
@@ -349,7 +329,7 @@ const Contact = () => {
? "border-red-400 focus:ring-red-400" ? "border-red-400 focus:ring-red-400"
: "border-white/60 focus:ring-liquid-blue focus:border-transparent" : "border-white/60 focus:ring-liquid-blue focus:border-transparent"
}`} }`}
placeholder={tForm("placeholders.subject")} placeholder="What's this about?"
aria-invalid={ aria-invalid={
errors.subject && touched.subject ? "true" : "false" errors.subject && touched.subject ? "true" : "false"
} }
@@ -386,7 +366,7 @@ const Contact = () => {
? "border-red-400 focus:ring-red-400" ? "border-red-400 focus:ring-red-400"
: "border-white/60 focus:ring-liquid-blue focus:border-transparent" : "border-white/60 focus:ring-liquid-blue focus:border-transparent"
}`} }`}
placeholder={tForm("placeholders.message")} placeholder="Tell me more about your project or question..."
aria-invalid={ aria-invalid={
errors.message && touched.message ? "true" : "false" errors.message && touched.message ? "true" : "false"
} }
@@ -405,7 +385,7 @@ const Contact = () => {
<span></span> <span></span>
)} )}
<span className="text-xs text-stone-400"> <span className="text-xs text-stone-400">
{tForm("characters", { count: formData.message.length })} {formData.message.length} characters
</span> </span>
</div> </div>
</div> </div>
@@ -421,12 +401,12 @@ const Contact = () => {
{isSubmitting ? ( {isSubmitting ? (
<> <>
<div className="w-5 h-5 border-2 border-white/30 border-t-white rounded-full animate-spin"></div> <div className="w-5 h-5 border-2 border-white/30 border-t-white rounded-full animate-spin"></div>
<span>{tForm("sending")}</span> <span>Sending Message...</span>
</> </>
) : ( ) : (
<> <>
<Send size={20} /> <Send size={20} />
<span className="text-cream">{tForm("send")}</span> <span className="text-cream">Send Message</span>
</> </>
)} )}
</motion.button> </motion.button>

View File

@@ -1,157 +0,0 @@
"use client";
import { motion } from "framer-motion";
import { BookOpen } from "lucide-react";
import { useEffect, useState } from "react";
import { useTranslations } from "next-intl";
interface CurrentlyReading {
title: string;
authors: string[];
image: string | null;
progress: number;
startedAt: string | null;
}
const CurrentlyReading = () => {
const t = useTranslations("home.about.currentlyReading");
const [books, setBooks] = useState<CurrentlyReading[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
// Nur einmal beim Laden der Seite
const fetchCurrentlyReading = async () => {
try {
const res = await fetch("/api/n8n/hardcover/currently-reading", {
cache: "default",
});
if (!res.ok) {
throw new Error("Failed to fetch");
}
const data = await res.json();
// Handle both single book and array of books
if (data.currentlyReading) {
const booksArray = Array.isArray(data.currentlyReading)
? data.currentlyReading
: [data.currentlyReading];
setBooks(booksArray);
} else {
setBooks([]);
}
} catch (error) {
if (process.env.NODE_ENV === "development") {
console.error("Error fetching currently reading:", error);
}
setBooks([]);
} finally {
setLoading(false);
}
};
fetchCurrentlyReading();
}, []); // Leeres Array = nur einmal beim Mount
// Zeige nichts wenn kein Buch gelesen wird oder noch geladen wird
if (loading || books.length === 0) {
return null;
}
return (
<div className="space-y-4">
{/* Header */}
<div className="flex items-center gap-2 mb-4">
<BookOpen size={18} className="text-stone-600 flex-shrink-0" />
<h3 className="text-lg font-bold text-stone-900">
{t("title")} {books.length > 1 && `(${books.length})`}
</h3>
</div>
{/* Books List */}
{books.map((book, index) => (
<motion.div
key={`${book.title}-${index}`}
initial={{ opacity: 0, y: 20 }}
whileInView={{ opacity: 1, y: 0 }}
viewport={{ once: true, margin: "-50px" }}
transition={{ duration: 0.6, delay: index * 0.1, ease: [0.25, 0.1, 0.25, 1] }}
whileHover={{
scale: 1.02,
transition: { duration: 0.4, ease: "easeOut" },
}}
className="relative overflow-hidden bg-gradient-to-br from-liquid-lavender/15 via-liquid-pink/10 to-liquid-rose/15 border-2 border-liquid-lavender/30 rounded-xl p-6 backdrop-blur-sm hover:border-liquid-lavender/50 hover:from-liquid-lavender/20 hover:via-liquid-pink/15 hover:to-liquid-rose/20 transition-all duration-500 ease-out"
>
{/* Background Blob Animation */}
<motion.div
className="absolute -top-10 -right-10 w-32 h-32 bg-gradient-to-br from-liquid-lavender/20 to-liquid-pink/20 rounded-full blur-2xl"
animate={{
scale: [1, 1.2, 1],
opacity: [0.3, 0.5, 0.3],
}}
transition={{
duration: 8,
repeat: Infinity,
ease: "easeInOut",
delay: index * 0.5,
}}
/>
<div className="relative z-10 flex flex-col sm:flex-row gap-4 items-start">
{/* Book Cover */}
{book.image && (
<motion.div
initial={{ opacity: 0, scale: 0.9 }}
animate={{ opacity: 1, scale: 1 }}
transition={{ duration: 0.5, delay: 0.2 + index * 0.1 }}
className="flex-shrink-0"
>
<div className="relative w-24 h-36 sm:w-28 sm:h-40 rounded-lg overflow-hidden shadow-lg border-2 border-white/50">
<img
src={book.image}
alt={book.title}
className="w-full h-full object-cover"
loading="lazy"
/>
{/* Glossy Overlay */}
<div className="absolute inset-0 bg-gradient-to-tr from-white/20 via-transparent to-white/10 pointer-events-none" />
</div>
</motion.div>
)}
{/* Book Info */}
<div className="flex-1 min-w-0">
{/* Title */}
<h4 className="text-lg font-bold text-stone-900 mb-1 line-clamp-2">
{book.title}
</h4>
{/* Authors */}
<p className="text-sm text-stone-600 mb-4 line-clamp-1">
{book.authors.join(", ")}
</p>
{/* Progress Bar */}
<div className="space-y-2">
<div className="flex items-center justify-between text-xs text-stone-600">
<span>{t("progress")}</span>
<span className="font-semibold">{book.progress}%</span>
</div>
<div className="relative h-2 bg-white/50 rounded-full overflow-hidden border border-white/70">
<motion.div
initial={{ width: 0 }}
animate={{ width: `${book.progress}%` }}
transition={{ duration: 1, delay: 0.3 + index * 0.1, ease: "easeOut" }}
className="absolute left-0 top-0 h-full bg-gradient-to-r from-liquid-lavender via-liquid-pink to-liquid-rose rounded-full shadow-sm"
/>
</div>
</div>
</div>
</div>
</motion.div>
))}
</div>
);
};
export default CurrentlyReading;

View File

@@ -1,25 +1,29 @@
"use client"; "use client";
import { useState } from 'react'; import { useState, useEffect } from 'react';
import { motion } from 'framer-motion'; import { motion } from 'framer-motion';
import { Heart, Code } from 'lucide-react'; import { Heart, Code } from 'lucide-react';
import { SiGithub, SiLinkedin } from 'react-icons/si'; import { SiGithub, SiLinkedin } from 'react-icons/si';
import Link from 'next/link'; import Link from 'next/link';
import { useLocale, useTranslations } from "next-intl";
import { useConsent } from "./ConsentProvider";
const Footer = () => { const Footer = () => {
const locale = useLocale(); const [currentYear, setCurrentYear] = useState(2024);
const t = useTranslations("footer"); const [mounted, setMounted] = useState(false);
const { resetConsent } = useConsent();
const [currentYear] = useState(() => new Date().getFullYear()); useEffect(() => {
setCurrentYear(new Date().getFullYear());
setMounted(true);
}, []);
const socialLinks = [ const socialLinks = [
{ icon: SiGithub, href: 'https://github.com/Denshooter', label: 'GitHub' }, { icon: SiGithub, href: 'https://github.com/Denshooter', label: 'GitHub' },
{ icon: SiLinkedin, href: 'https://linkedin.com/in/dkonkol', label: 'LinkedIn' } { icon: SiLinkedin, href: 'https://linkedin.com/in/dkonkol', label: 'LinkedIn' }
]; ];
if (!mounted) {
return null;
}
return ( return (
<footer className="relative py-12 px-4 bg-white border-t border-stone-200"> <footer className="relative py-12 px-4 bg-white border-t border-stone-200">
<div className="max-w-7xl mx-auto"> <div className="max-w-7xl mx-auto">
@@ -40,10 +44,10 @@ const Footer = () => {
<Code className="w-6 h-6 text-stone-800" /> <Code className="w-6 h-6 text-stone-800" />
</motion.div> </motion.div>
<div> <div>
<Link href={`/${locale}`} className="text-xl font-bold font-mono text-stone-800 hover:text-liquid-blue transition-colors"> <Link href="/" className="text-xl font-bold font-mono text-stone-800 hover:text-liquid-blue transition-colors">
dk<span className="text-liquid-rose">0</span> dk<span className="text-liquid-rose">0</span>
</Link> </Link>
<p className="text-xs text-stone-500">{t("role")}</p> <p className="text-xs text-stone-500">Software Engineer</p>
</div> </div>
</motion.div> </motion.div>
@@ -86,7 +90,7 @@ const Footer = () => {
> >
<Heart size={14} className="text-liquid-rose fill-liquid-rose" /> <Heart size={14} className="text-liquid-rose fill-liquid-rose" />
</motion.div> </motion.div>
<span>{t("madeIn")}</span> <span>Made in Germany</span>
</motion.div> </motion.div>
</div> </div>
@@ -100,25 +104,17 @@ const Footer = () => {
> >
<div className="flex space-x-6 text-sm"> <div className="flex space-x-6 text-sm">
<Link <Link
href={`/${locale}/legal-notice`} href="/legal-notice"
className="text-stone-500 hover:text-stone-800 transition-colors duration-200" className="text-stone-500 hover:text-stone-800 transition-colors duration-200"
> >
{t("legalNotice")} Impressum
</Link> </Link>
<Link <Link
href={`/${locale}/privacy-policy`} href="/privacy-policy"
className="text-stone-500 hover:text-stone-800 transition-colors duration-200" className="text-stone-500 hover:text-stone-800 transition-colors duration-200"
> >
{t("privacyPolicy")} Privacy Policy
</Link> </Link>
<button
type="button"
onClick={() => resetConsent()}
className="text-stone-500 hover:text-stone-800 transition-colors duration-200"
title={t("privacySettingsTitle")}
>
{t("privacySettings")}
</button>
<Link <Link
href="/404" href="/404"
className="text-stone-500 hover:text-stone-800 transition-colors duration-200 font-mono text-xs" className="text-stone-500 hover:text-stone-800 transition-colors duration-200 font-mono text-xs"
@@ -129,7 +125,7 @@ const Footer = () => {
</div> </div>
<div className="text-xs text-stone-400 flex items-center space-x-1"> <div className="text-xs text-stone-400 flex items-center space-x-1">
<span>{t("builtWith")}</span> <span>Built with</span>
<span className="text-stone-600 font-semibold">Next.js</span> <span className="text-stone-600 font-semibold">Next.js</span>
<span className="text-stone-300"></span> <span className="text-stone-300"></span>
<span className="text-stone-600 font-semibold">TypeScript</span> <span className="text-stone-600 font-semibold">TypeScript</span>

View File

@@ -5,18 +5,18 @@ import { motion, AnimatePresence } from "framer-motion";
import { Menu, X, Mail } from "lucide-react"; import { Menu, X, Mail } from "lucide-react";
import { SiGithub, SiLinkedin } from "react-icons/si"; import { SiGithub, SiLinkedin } from "react-icons/si";
import Link from "next/link"; import Link from "next/link";
import { useLocale, useTranslations } from "next-intl";
import { usePathname, useSearchParams } from "next/navigation";
const Header = () => { const Header = () => {
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const [scrolled, setScrolled] = useState(false); const [scrolled, setScrolled] = useState(false);
const locale = useLocale(); const [mounted, setMounted] = useState(false);
const pathname = usePathname();
const searchParams = useSearchParams();
const t = useTranslations("nav");
const isHome = pathname === `/${locale}` || pathname === `/${locale}/`; useEffect(() => {
// Use requestAnimationFrame to ensure smooth transition
requestAnimationFrame(() => {
setMounted(true);
});
}, []);
useEffect(() => { useEffect(() => {
const handleScroll = () => { const handleScroll = () => {
@@ -28,10 +28,10 @@ const Header = () => {
}, []); }, []);
const navItems = [ const navItems = [
{ name: t("home"), href: `/${locale}` }, { name: "Home", href: "/" },
{ name: t("about"), href: isHome ? "#about" : `/${locale}#about` }, { name: "About", href: "#about" },
{ name: t("projects"), href: isHome ? "#projects" : `/${locale}/projects` }, { name: "Projects", href: "#projects" },
{ name: t("contact"), href: isHome ? "#contact" : `/${locale}#contact` }, { name: "Contact", href: "#contact" },
]; ];
const socialLinks = [ const socialLinks = [
@@ -44,21 +44,16 @@ const Header = () => {
{ icon: Mail, href: "mailto:contact@dk0.dev", label: "Email" }, { icon: Mail, href: "mailto:contact@dk0.dev", label: "Email" },
]; ];
const pathWithoutLocale = pathname.replace(new RegExp(`^/${locale}`), "") || "";
const qs = searchParams.toString();
const query = qs ? `?${qs}` : "";
const enHref = `/en${pathWithoutLocale}${query}`;
const deHref = `/de${pathWithoutLocale}${query}`;
// Always render to prevent flash, but use opacity transition // Always render to prevent flash, but use opacity transition
return ( return (
<> <>
<motion.header <motion.header
initial={false} initial={false}
animate={{ y: 0, opacity: 1 }} animate={{ y: 0, opacity: mounted ? 1 : 0 }}
transition={{ duration: 0.3, ease: "easeOut" }} transition={{ duration: 0.3, ease: "easeOut" }}
className="fixed top-6 left-0 right-0 z-50 flex justify-center px-4 pointer-events-none" className="fixed top-6 left-0 right-0 z-50 flex justify-center px-4 pointer-events-none"
style={{ opacity: mounted ? 1 : 0 }}
> >
<div <div
className={`pointer-events-auto transition-all duration-500 ease-out ${ className={`pointer-events-auto transition-all duration-500 ease-out ${
@@ -67,7 +62,7 @@ const Header = () => {
> >
<motion.div <motion.div
initial={false} initial={false}
animate={{ opacity: 1, y: 0 }} animate={{ opacity: mounted ? 1 : 0, y: 0 }}
transition={{ duration: 0.3, ease: "easeOut" }} transition={{ duration: 0.3, ease: "easeOut" }}
className={` className={`
backdrop-blur-xl transition-all duration-500 backdrop-blur-xl transition-all duration-500
@@ -84,7 +79,7 @@ const Header = () => {
className="flex items-center space-x-2" className="flex items-center space-x-2"
> >
<Link <Link
href={`/${locale}`} href="/"
className="text-2xl font-black font-sans text-stone-900 tracking-tighter liquid-hover flex items-center" className="text-2xl font-black font-sans text-stone-900 tracking-tighter liquid-hover flex items-center"
> >
dk<span className="text-red-500">0</span> dk<span className="text-red-500">0</span>
@@ -131,30 +126,6 @@ const Header = () => {
</nav> </nav>
<div className="hidden md:flex items-center space-x-3"> <div className="hidden md:flex items-center space-x-3">
<div className="flex items-center bg-white/40 border border-white/50 rounded-full overflow-hidden shadow-sm">
<Link
href={enHref}
className={`px-3 py-1.5 text-xs font-semibold transition-colors ${
locale === "en"
? "bg-stone-900 text-stone-50"
: "text-stone-700 hover:bg-white/60"
}`}
aria-label="Switch language to English"
>
EN
</Link>
<Link
href={deHref}
className={`px-3 py-1.5 text-xs font-semibold transition-colors ${
locale === "de"
? "bg-stone-900 text-stone-50"
: "text-stone-700 hover:bg-white/60"
}`}
aria-label="Sprache auf Deutsch umstellen"
>
DE
</Link>
</div>
{socialLinks.map((social) => ( {socialLinks.map((social) => (
<motion.a <motion.a
key={social.label} key={social.label}
@@ -174,7 +145,6 @@ const Header = () => {
whileTap={{ scale: 0.95 }} whileTap={{ scale: 0.95 }}
onClick={() => setIsOpen(!isOpen)} onClick={() => setIsOpen(!isOpen)}
className="md:hidden p-2 rounded-full bg-white/40 hover:bg-white/60 text-stone-800 transition-colors liquid-hover" className="md:hidden p-2 rounded-full bg-white/40 hover:bg-white/60 text-stone-800 transition-colors liquid-hover"
aria-label={isOpen ? "Close menu" : "Open menu"}
> >
{isOpen ? <X size={24} /> : <Menu size={24} />} {isOpen ? <X size={24} /> : <Menu size={24} />}
</motion.button> </motion.button>

View File

@@ -2,42 +2,13 @@
import { motion } from "framer-motion"; import { motion } from "framer-motion";
import { ArrowDown, Code, Zap, Rocket } from "lucide-react"; import { ArrowDown, Code, Zap, Rocket } from "lucide-react";
import { useEffect, useState } from "react"; import Image from "next/image";
import { useLocale, useTranslations } from "next-intl";
import type { JSONContent } from "@tiptap/react";
import RichTextClient from "./RichTextClient";
const Hero = () => { const Hero = () => {
const locale = useLocale();
const t = useTranslations("home.hero");
const [cmsDoc, setCmsDoc] = useState<JSONContent | null>(null);
useEffect(() => {
(async () => {
try {
const res = await fetch(
`/api/content/page?key=${encodeURIComponent("home-hero")}&locale=${encodeURIComponent(locale)}`,
);
const data = await res.json();
// Only use CMS content if it exists for the active locale.
// If the API falls back to another locale, keep showing next-intl strings
// so the locale switch visibly changes the page.
if (data?.content?.content && data?.content?.locale === locale) {
setCmsDoc(data.content.content as JSONContent);
} else {
setCmsDoc(null);
}
} catch {
// ignore; fallback to static
setCmsDoc(null);
}
})();
}, [locale]);
const features = [ const features = [
{ icon: Code, text: t("features.f1") }, { icon: Code, text: "Next.js & Flutter" },
{ icon: Zap, text: t("features.f2") }, { icon: Zap, text: "Docker Swarm & CI/CD" },
{ icon: Rocket, text: t("features.f3") }, { icon: Rocket, text: "Self-Hosted Infrastructure" },
]; ];
return ( return (
@@ -110,13 +81,12 @@ const Hero = () => {
repeatType: "reverse", repeatType: "reverse",
}} }}
> >
{/* Use a plain <img> to fully bypass Next.js image optimizer (dev 400 issue). */} <Image
<img
src="/images/me.jpg" src="/images/me.jpg"
alt="Dennis Konkol" alt="Dennis Konkol"
className="absolute inset-0 w-full h-full object-cover scale-105 hover:scale-[1.08] transition-transform duration-1000 ease-out" fill
loading="eager" className="object-cover scale-105 hover:scale-[1.08] transition-transform duration-1000 ease-out"
decoding="async" priority
/> />
{/* Glossy Overlay for Liquid Feel */} {/* Glossy Overlay for Liquid Feel */}
@@ -176,18 +146,26 @@ const Hero = () => {
</motion.div> </motion.div>
{/* Description */} {/* Description */}
<motion.div <motion.p
initial={{ opacity: 0, y: 20 }} initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }} animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.6, delay: 0.3, ease: [0.25, 0.1, 0.25, 1] }} transition={{ duration: 0.6, delay: 0.3, ease: [0.25, 0.1, 0.25, 1] }}
className="text-lg md:text-xl text-stone-700 mb-12 max-w-2xl mx-auto leading-relaxed" className="text-lg md:text-xl text-stone-700 mb-12 max-w-2xl mx-auto leading-relaxed"
> >
{cmsDoc ? ( Student and passionate{" "}
<RichTextClient doc={cmsDoc} className="prose prose-stone max-w-none" /> <span className="text-stone-900 font-semibold decoration-liquid-mint decoration-2 underline underline-offset-4">
) : ( self-hoster
<p>{t("description")}</p> </span>{" "}
)} building full-stack web apps and mobile solutions. I run my own{" "}
</motion.div> <span className="text-stone-900 font-semibold decoration-liquid-lavender decoration-2 underline underline-offset-4">
infrastructure
</span>{" "}
and love exploring{" "}
<span className="text-stone-900 font-semibold decoration-liquid-rose decoration-2 underline underline-offset-4">
DevOps
</span>
.
</motion.p>
{/* Features */} {/* Features */}
<motion.div <motion.div
@@ -231,7 +209,7 @@ const Hero = () => {
transition={{ duration: 0.3, ease: "easeOut" }} transition={{ duration: 0.3, ease: "easeOut" }}
className="px-8 py-4 bg-stone-900 text-cream rounded-full shadow-lg hover:shadow-xl hover:bg-stone-950 transition-all duration-500 flex items-center gap-2" className="px-8 py-4 bg-stone-900 text-cream rounded-full shadow-lg hover:shadow-xl hover:bg-stone-950 transition-all duration-500 flex items-center gap-2"
> >
<span className="text-cream">{t("ctaWork")}</span> <span className="text-cream">View My Work</span>
<ArrowDown size={18} /> <ArrowDown size={18} />
</motion.a> </motion.a>
@@ -242,7 +220,7 @@ const Hero = () => {
transition={{ duration: 0.3, ease: "easeOut" }} transition={{ duration: 0.3, ease: "easeOut" }}
className="px-8 py-4 bg-white text-stone-900 border border-stone-200 rounded-full font-medium shadow-sm hover:shadow-md transition-all duration-500" className="px-8 py-4 bg-white text-stone-900 border border-stone-200 rounded-full font-medium shadow-sm hover:shadow-md transition-all duration-500"
> >
<span>{t("ctaContact")}</span> <span>Contact Me</span>
</motion.a> </motion.a>
</motion.div> </motion.div>
</div> </div>

View File

@@ -35,6 +35,7 @@ export default function KernelPanic404Wrapper() {
backgroundColor: "#020202", backgroundColor: "#020202",
}} }}
data-404-page="true" data-404-page="true"
allowTransparency={false}
/> />
); );
} }

View File

@@ -5,7 +5,6 @@ import { motion, Variants } from "framer-motion";
import { ExternalLink, Github, ArrowRight, Calendar } from "lucide-react"; import { ExternalLink, Github, ArrowRight, Calendar } from "lucide-react";
import Link from "next/link"; import Link from "next/link";
import Image from "next/image"; import Image from "next/image";
import { useLocale, useTranslations } from "next-intl";
const fadeInUp: Variants = { const fadeInUp: Variants = {
hidden: { opacity: 0, y: 20 }, hidden: { opacity: 0, y: 20 },
@@ -32,7 +31,6 @@ const staggerContainer: Variants = {
interface Project { interface Project {
id: number; id: number;
slug: string;
title: string; title: string;
description: string; description: string;
content: string; content: string;
@@ -47,8 +45,6 @@ interface Project {
const Projects = () => { const Projects = () => {
const [projects, setProjects] = useState<Project[]>([]); const [projects, setProjects] = useState<Project[]>([]);
const locale = useLocale();
const t = useTranslations("home.projects");
useEffect(() => { useEffect(() => {
const loadProjects = async () => { const loadProjects = async () => {
@@ -83,10 +79,11 @@ const Projects = () => {
className="text-center mb-20" className="text-center mb-20"
> >
<h2 className="text-4xl md:text-6xl font-bold mb-6 text-stone-900"> <h2 className="text-4xl md:text-6xl font-bold mb-6 text-stone-900">
{t("title")} Selected Works
</h2> </h2>
<p className="text-lg text-stone-600 max-w-2xl mx-auto mt-4 font-light"> <p className="text-lg text-stone-600 max-w-2xl mx-auto mt-4 font-light">
{t("subtitle")} A collection of projects I&apos;ve worked on, ranging from web
applications to experiments.
</p> </p>
</motion.div> </motion.div>
@@ -102,7 +99,7 @@ const Projects = () => {
key={project.id} key={project.id}
variants={fadeInUp} variants={fadeInUp}
whileHover={{ y: -8 }} whileHover={{ y: -8 }}
className="group flex flex-col bg-white/40 backdrop-blur-xl rounded-2xl overflow-hidden border border-white/60 shadow-[0_4px_20px_rgba(0,0,0,0.02)] hover:shadow-[0_20px_40px_rgba(0,0,0,0.06)] transition-[box-shadow,border-color,background-color] duration-500" className="group flex flex-col bg-white/40 backdrop-blur-xl rounded-2xl overflow-hidden border border-white/60 shadow-[0_4px_20px_rgba(0,0,0,0.02)] hover:shadow-[0_20px_40px_rgba(0,0,0,0.06)] transition-all duration-500"
> >
{/* Project Cover / Image Area */} {/* Project Cover / Image Area */}
<div className="relative aspect-[16/10] overflow-hidden bg-stone-100"> <div className="relative aspect-[16/10] overflow-hidden bg-stone-100">
@@ -140,7 +137,7 @@ const Projects = () => {
{project.featured && ( {project.featured && (
<div className="absolute top-3 left-3 z-20"> <div className="absolute top-3 left-3 z-20">
<div className="px-3 py-1 bg-[#292524]/80 backdrop-blur-md text-[#fdfcf8] text-[10px] font-bold uppercase tracking-widest rounded-full shadow-sm border border-white/10"> <div className="px-3 py-1 bg-[#292524]/80 backdrop-blur-md text-[#fdfcf8] text-[10px] font-bold uppercase tracking-widest rounded-full shadow-sm border border-white/10">
{t("featured")} Featured
</div> </div>
</div> </div>
)} )}
@@ -178,7 +175,7 @@ const Projects = () => {
<div className="p-6 flex flex-col flex-1"> <div className="p-6 flex flex-col flex-1">
{/* Stretched Link covering the whole card (including image area) */} {/* Stretched Link covering the whole card (including image area) */}
<Link <Link
href={`/${locale}/projects/${project.slug}`} href={`/projects/${project.title.toLowerCase().replace(/[^a-z0-9]+/g, '-')}`}
className="absolute inset-0 z-10" className="absolute inset-0 z-10"
aria-label={`View project ${project.title}`} aria-label={`View project ${project.title}`}
/> />
@@ -250,10 +247,10 @@ const Projects = () => {
className="mt-16 text-center" className="mt-16 text-center"
> >
<Link <Link
href={`/${locale}/projects`} href="/projects"
className="inline-flex items-center gap-2 px-8 py-4 bg-white border border-stone-200 rounded-full text-stone-700 font-medium hover:bg-stone-50 hover:border-stone-300 hover:gap-3 transition-all duration-500 ease-out shadow-sm hover:shadow-md" className="inline-flex items-center gap-2 px-8 py-4 bg-white border border-stone-200 rounded-full text-stone-700 font-medium hover:bg-stone-50 hover:border-stone-300 hover:gap-3 transition-all duration-500 ease-out shadow-sm hover:shadow-md"
> >
{t("viewAll")} <ArrowRight size={16} /> View All Projects <ArrowRight size={16} />
</Link> </Link>
</motion.div> </motion.div>
</div> </div>

View File

@@ -1,21 +0,0 @@
import React from "react";
import type { JSONContent } from "@tiptap/react";
import { richTextToSafeHtml } from "@/lib/richtext";
export default function RichText({
doc,
className,
}: {
doc: JSONContent;
className?: string;
}) {
const html = richTextToSafeHtml(doc);
return (
<div
className={className}
// HTML is sanitized in `richTextToSafeHtml`
dangerouslySetInnerHTML={{ __html: html }}
/>
);
}

View File

@@ -1,24 +0,0 @@
"use client";
import React, { useMemo } from "react";
import type { JSONContent } from "@tiptap/react";
import { richTextToSafeHtml } from "@/lib/richtext";
export default function RichTextClient({
doc,
className,
}: {
doc: JSONContent;
className?: string;
}) {
const html = useMemo(() => richTextToSafeHtml(doc), [doc]);
return (
<div
className={className}
// HTML is sanitized in `richTextToSafeHtml`
dangerouslySetInnerHTML={{ __html: html }}
/>
);
}

View File

@@ -50,7 +50,6 @@ interface Project {
function EditorPageContent() { function EditorPageContent() {
const searchParams = useSearchParams(); const searchParams = useSearchParams();
const projectId = searchParams.get("id"); const projectId = searchParams.get("id");
const initialLocale = searchParams.get("locale") || "en";
const contentRef = useRef<HTMLDivElement>(null); const contentRef = useRef<HTMLDivElement>(null);
const { showSuccess, showError } = useToast(); const { showSuccess, showError } = useToast();
@@ -59,8 +58,6 @@ function EditorPageContent() {
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const [isSaving, setIsSaving] = useState(false); const [isSaving, setIsSaving] = useState(false);
const [isCreating, setIsCreating] = useState(!projectId); const [isCreating, setIsCreating] = useState(!projectId);
const [editLocale, setEditLocale] = useState(initialLocale);
const [baseTexts, setBaseTexts] = useState<{ title: string; description: string } | null>(null);
const [showPreview, setShowPreview] = useState(false); const [showPreview, setShowPreview] = useState(false);
const [_isTyping, setIsTyping] = useState(false); const [_isTyping, setIsTyping] = useState(false);
const [history, setHistory] = useState<typeof formData[]>([]); const [history, setHistory] = useState<typeof formData[]>([]);
@@ -93,10 +90,6 @@ function EditorPageContent() {
); );
if (foundProject) { if (foundProject) {
setBaseTexts({
title: foundProject.title || "",
description: foundProject.description || "",
});
const initialData = { const initialData = {
title: foundProject.title || "", title: foundProject.title || "",
description: foundProject.description || "", description: foundProject.description || "",
@@ -134,30 +127,6 @@ function EditorPageContent() {
} }
}, []); }, []);
const loadTranslation = useCallback(async (id: string, locale: string) => {
if (!id || !locale || locale === "en") return;
try {
const response = await fetch(`/api/projects/${id}/translation?locale=${encodeURIComponent(locale)}`, {
headers: {
"x-admin-request": "true",
"x-session-token": sessionStorage.getItem("admin_session_token") || "",
},
});
if (!response.ok) return;
const data = await response.json();
const tr = data.translation as { title?: string; description?: string } | null;
if (tr?.title && tr?.description) {
setFormData((prev) => ({
...prev,
title: tr.title || prev.title,
description: tr.description || prev.description,
}));
}
} catch {
// ignore translation load failures
}
}, []);
// Check authentication and load project // Check authentication and load project
useEffect(() => { useEffect(() => {
const init = async () => { const init = async () => {
@@ -172,7 +141,6 @@ function EditorPageContent() {
// Load project if editing // Load project if editing
if (projectId) { if (projectId) {
await loadProject(projectId); await loadProject(projectId);
await loadTranslation(projectId, editLocale);
} else { } else {
setIsCreating(true); setIsCreating(true);
// Initialize history for new project // Initialize history for new project
@@ -214,7 +182,7 @@ function EditorPageContent() {
}; };
init(); init();
}, [projectId, loadProject, loadTranslation, editLocale]); }, [projectId, loadProject]);
const handleSave = useCallback(async () => { const handleSave = useCallback(async () => {
try { try {
@@ -237,13 +205,9 @@ function EditorPageContent() {
const method = projectId ? "PUT" : "POST"; const method = projectId ? "PUT" : "POST";
// Prepare data for saving - only include fields that exist in the database schema // Prepare data for saving - only include fields that exist in the database schema
const saveTitle = editLocale === "en" ? formData.title.trim() : (baseTexts?.title || formData.title.trim());
const saveDescription =
editLocale === "en" ? formData.description.trim() : (baseTexts?.description || formData.description.trim());
const saveData = { const saveData = {
title: saveTitle, title: formData.title.trim(),
description: saveDescription, description: formData.description.trim(),
content: formData.content.trim(), content: formData.content.trim(),
category: formData.category, category: formData.category,
tags: formData.tags, tags: formData.tags,
@@ -261,7 +225,6 @@ function EditorPageContent() {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"x-admin-request": "true", "x-admin-request": "true",
"x-session-token": sessionStorage.getItem("admin_session_token") || "",
}, },
body: JSON.stringify(saveData), body: JSON.stringify(saveData),
}); });
@@ -287,27 +250,6 @@ function EditorPageContent() {
// Show success toast (smaller, smoother) // Show success toast (smaller, smoother)
showSuccess("Saved", `"${savedProject.title}" saved`); showSuccess("Saved", `"${savedProject.title}" saved`);
// Save translation if editing a non-default locale
if (projectId && editLocale !== "en") {
try {
await fetch(`/api/projects/${projectId}/translation`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
"x-admin-request": "true",
"x-session-token": sessionStorage.getItem("admin_session_token") || "",
},
body: JSON.stringify({
locale: editLocale,
title: formData.title.trim(),
description: formData.description.trim(),
}),
});
} catch {
// ignore translation save failures
}
}
// Update project ID if it was a new project // Update project ID if it was a new project
if (!projectId && savedProject.id) { if (!projectId && savedProject.id) {
@@ -332,7 +274,7 @@ function EditorPageContent() {
} finally { } finally {
setIsSaving(false); setIsSaving(false);
} }
}, [projectId, formData, showSuccess, showError, editLocale, baseTexts]); }, [projectId, formData, showSuccess, showError]);
const handleInputChange = ( const handleInputChange = (
field: string, field: string,
@@ -702,34 +644,6 @@ function EditorPageContent() {
</h3> </h3>
<div className="space-y-4"> <div className="space-y-4">
<div>
<label className="block text-sm font-medium text-stone-300 mb-2">
Language
</label>
<div className="custom-select">
<select
value={editLocale}
onChange={(e) => {
const next = e.target.value;
setEditLocale(next);
if (projectId) {
// Update URL for deep-linking and reload translation
const newUrl = `/editor?id=${projectId}&locale=${encodeURIComponent(next)}`;
window.history.replaceState({}, "", newUrl);
loadTranslation(projectId, next);
}
}}
>
<option value="en">English (default)</option>
<option value="de">Deutsch</option>
</select>
</div>
{editLocale !== "en" && (
<p className="text-xs text-stone-400 mt-2">
Title/description are saved as a translation. Other fields are global.
</p>
)}
</div>
<div> <div>
<label className="block text-sm font-medium text-stone-300 mb-2"> <label className="block text-sm font-medium text-stone-300 mb-2">
Category Category

View File

@@ -3,25 +3,27 @@ import { Metadata } from "next";
import { Inter } from "next/font/google"; import { Inter } from "next/font/google";
import React from "react"; import React from "react";
import ClientProviders from "./components/ClientProviders"; import ClientProviders from "./components/ClientProviders";
import { cookies } from "next/headers";
import { getBaseUrl } from "@/lib/seo";
const inter = Inter({ const inter = Inter({
variable: "--font-inter", variable: "--font-inter",
subsets: ["latin"], subsets: ["latin"],
}); });
export default async function RootLayout({ export default function RootLayout({
children, children,
}: { }: {
children: React.ReactNode; children: React.ReactNode;
}) { }) {
const cookieStore = await cookies();
const locale = cookieStore.get("NEXT_LOCALE")?.value || "en";
return ( return (
<html lang={locale}> <html lang="en">
<head> <head>
<script
defer
src="https://analytics.dk0.dev/script.js"
data-website-id="b3665829-927a-4ada-b9bb-fcf24171061e"
></script>
<meta charSet="utf-8" /> <meta charSet="utf-8" />
<title>Dennis Konkol&#39;s Portfolio</title>
</head> </head>
<body className={inter.variable} suppressHydrationWarning> <body className={inter.variable} suppressHydrationWarning>
<ClientProviders>{children}</ClientProviders> <ClientProviders>{children}</ClientProviders>
@@ -31,7 +33,6 @@ export default async function RootLayout({
} }
export const metadata: Metadata = { export const metadata: Metadata = {
metadataBase: new URL(getBaseUrl()),
title: "Dennis Konkol | Portfolio", title: "Dennis Konkol | Portfolio",
description: description:
"Portfolio of Dennis Konkol, a student and software engineer based in Osnabrück, Germany. Passionate about technology, coding, and solving real-world problems.", "Portfolio of Dennis Konkol, a student and software engineer based in Osnabrück, Germany. Passionate about technology, coding, and solving real-world problems.",

View File

@@ -6,40 +6,8 @@ import { ArrowLeft } from 'lucide-react';
import Header from "../components/Header"; import Header from "../components/Header";
import Footer from "../components/Footer"; import Footer from "../components/Footer";
import Link from "next/link"; import Link from "next/link";
import { useLocale, useTranslations } from "next-intl";
import { useEffect, useState } from "react";
import type { JSONContent } from "@tiptap/react";
import RichTextClient from "../components/RichTextClient";
export default function LegalNotice() { export default function LegalNotice() {
const locale = useLocale();
const t = useTranslations("common");
const [cmsDoc, setCmsDoc] = useState<JSONContent | null>(null);
const [cmsTitle, setCmsTitle] = useState<string | null>(null);
useEffect(() => {
(async () => {
try {
const res = await fetch(
`/api/content/page?key=${encodeURIComponent("legal-notice")}&locale=${encodeURIComponent(locale)}`,
);
const data = await res.json();
// Only use CMS content if it exists for the active locale.
if (data?.content?.content && data?.content?.locale === locale) {
setCmsDoc(data.content.content as JSONContent);
setCmsTitle((data.content.title as string | null) ?? null);
} else {
setCmsDoc(null);
setCmsTitle(null);
}
} catch {
// ignore; fallback to static content
setCmsDoc(null);
setCmsTitle(null);
}
})();
}, [locale]);
return ( return (
<div className="min-h-screen animated-bg"> <div className="min-h-screen animated-bg">
<Header /> <Header />
@@ -51,15 +19,15 @@ export default function LegalNotice() {
className="mb-8" className="mb-8"
> >
<Link <Link
href={`/${locale}`} href="/"
className="inline-flex items-center space-x-2 text-blue-400 hover:text-blue-300 transition-colors mb-6" className="inline-flex items-center space-x-2 text-blue-400 hover:text-blue-300 transition-colors mb-6"
> >
<ArrowLeft size={20} /> <ArrowLeft size={20} />
<span>{t("backToHome")}</span> <span>Back to Home</span>
</Link> </Link>
<h1 className="text-4xl md:text-5xl font-bold mb-6 gradient-text"> <h1 className="text-4xl md:text-5xl font-bold mb-6 gradient-text">
{cmsTitle || "Impressum"} Impressum
</h1> </h1>
</motion.div> </motion.div>
@@ -69,68 +37,47 @@ export default function LegalNotice() {
transition={{ duration: 0.8, delay: 0.2 }} transition={{ duration: 0.8, delay: 0.2 }}
className="glass-card p-8 rounded-2xl space-y-6" className="glass-card p-8 rounded-2xl space-y-6"
> >
{cmsDoc ? ( <div className="text-gray-300 leading-relaxed">
<RichTextClient doc={cmsDoc} className="prose prose-invert max-w-none text-gray-300" /> <h2 className="text-2xl font-semibold mb-4">
) : ( Verantwortlicher für die Inhalte dieser Website
<> </h2>
<div className="text-gray-300 leading-relaxed"> <div className="space-y-2 text-gray-300">
<h2 className="text-2xl font-semibold mb-4">Verantwortlicher für die Inhalte dieser Website</h2> <p><strong>Name:</strong> Dennis Konkol</p>
<div className="space-y-2 text-gray-300"> <p><strong>Adresse:</strong> Auf dem Ziegenbrink 2B, 49082 Osnabrück, Deutschland</p>
<p> <p><strong>E-Mail:</strong> <Link href="mailto:info@dki.one" className="text-blue-400 hover:text-blue-300 transition-colors">info@dk0.dev</Link></p>
<strong>Name:</strong> Dennis Konkol <p><strong>Website:</strong> <Link href="https://www.dk0.dev" className="text-blue-400 hover:text-blue-300 transition-colors">dk0.dev</Link></p>
</p> </div>
<p> </div>
<strong>Adresse:</strong> Auf dem Ziegenbrink 2B, 49082 Osnabrück, Deutschland
</p>
<p>
<strong>E-Mail:</strong>{" "}
<Link href="mailto:info@dki.one" className="text-blue-400 hover:text-blue-300 transition-colors">
info@dk0.dev
</Link>
</p>
<p>
<strong>Website:</strong>{" "}
<Link href="https://www.dk0.dev" className="text-blue-400 hover:text-blue-300 transition-colors">
dk0.dev
</Link>
</p>
</div>
</div>
<div className="text-gray-300"> <div className="text-gray-300">
<h2 className="text-2xl font-semibold mb-4">Haftung für Links</h2> <h2 className="text-2xl font-semiboldmb-4">Haftung für Links</h2>
<p className="leading-relaxed"> <p className="leading-relaxed">
Meine Website enthält Links auf externe Websites. Ich habe keinen Einfluss auf die Inhalte dieser Meine Website enthält Links auf externe Websites. Ich habe keinen Einfluss auf die Inhalte dieser Websites
Websites und kann daher keine Gewähr übernehmen. Für die Inhalte der verlinkten Seiten ist stets der und kann daher keine Gewähr übernehmen. Für die Inhalte der verlinkten Seiten ist stets der Betreiber oder
Betreiber oder Anbieter der Seiten verantwortlich. Jedoch überprüfe ich die verlinkten Seiten zum Anbieter der Seiten verantwortlich. Jedoch überprüfe ich die verlinkten Seiten zum Zeitpunkt der Verlinkung
Zeitpunkt der Verlinkung auf mögliche Rechtsverstöße. Bei Bekanntwerden von Rechtsverletzungen werde auf mögliche Rechtsverstöße. Bei Bekanntwerden von Rechtsverletzungen werde ich derartige Links umgehend entfernen.
ich derartige Links umgehend entfernen. </p>
</p> </div>
</div>
<div className="text-gray-300"> <div className="text-gray-300">
<h2 className="text-2xl font-semibold mb-4">Urheberrecht</h2> <h2 className="text-2xl font-semibold mb-4">Urheberrecht</h2>
<p className="leading-relaxed"> <p className="leading-relaxed">
Alle Inhalte dieser Website, einschließlich Texte, Fotos und Designs, stehen unter Alle Inhalte dieser Website, einschließlich Texte, Fotos und Designs, stehen unter Urheberrechtsschutz.
Urheberrechtsschutz. Jegliche Nutzung ohne vorherige schriftliche Zustimmung des Urhebers ist Jegliche Nutzung ohne vorherige schriftliche Zustimmung des Urhebers ist verboten.
verboten. </p>
</p> </div>
</div>
<div className="text-gray-300"> <div className="text-gray-300">
<h2 className="text-2xl font-semibold mb-4">Gewährleistung</h2> <h2 className="text-2xl font-semibold mb-4">Gewährleistung</h2>
<p className="leading-relaxed"> <p className="leading-relaxed">
Die Nutzung der Inhalte dieser Website erfolgt auf eigene Gefahr. Als Diensteanbieter kann ich keine Die Nutzung der Inhalte dieser Website erfolgt auf eigene Gefahr. Als Diensteanbieter kann ich keine
Gewähr übernehmen für Schäden, die entstehen können, durch den Zugriff oder die Nutzung dieser Gewähr übernehmen für Schäden, die entstehen können, durch den Zugriff oder die Nutzung dieser Website.
Website. </p>
</p> </div>
</div>
<div className="pt-4 border-t border-gray-700"> <div className="pt-4 border-t border-gray-700">
<p className="text-gray-400 text-sm">Letzte Aktualisierung: 12.02.2025</p> <p className="text-gray-400 text-sm">Letzte Aktualisierung: 12.02.2025</p>
</div> </div>
</>
)}
</motion.div> </motion.div>
</main> </main>
<Footer /> <Footer />

View File

@@ -32,15 +32,6 @@ export default function NotFound() {
setMounted(true); setMounted(true);
}, []); }, []);
// In tests, avoid next/dynamic loadable timing and render a stable fallback
if (process.env.NODE_ENV === "test") {
return (
<div>
Oops! The page you&apos;re looking for doesn&apos;t exist.
</div>
);
}
if (!mounted) { if (!mounted) {
return ( return (
<div style={{ <div style={{

View File

@@ -1,8 +1,171 @@
import { redirect } from "next/navigation"; "use client";
import { cookies } from "next/headers";
export default async function RootRedirectPage() { import Header from "./components/Header";
const cookieStore = await cookies(); import Hero from "./components/Hero";
const locale = cookieStore.get("NEXT_LOCALE")?.value || "en"; import About from "./components/About";
redirect(`/${locale}`); import Projects from "./components/Projects";
import Contact from "./components/Contact";
import Footer from "./components/Footer";
import Script from "next/script";
import ErrorBoundary from "@/components/ErrorBoundary";
import ActivityFeed from "./components/ActivityFeed";
import { motion } from "framer-motion";
export default function Home() {
return (
<div className="min-h-screen">
<Script
id={"structured-data"}
type="application/ld+json"
dangerouslySetInnerHTML={{
__html: JSON.stringify({
"@context": "https://schema.org",
"@type": "Person",
name: "Dennis Konkol",
url: "https://dk0.dev",
jobTitle: "Software Engineer",
address: {
"@type": "PostalAddress",
addressLocality: "Osnabrück",
addressCountry: "Germany",
},
sameAs: [
"https://github.com/Denshooter",
"https://linkedin.com/in/dkonkol",
],
}),
}}
/>
<ErrorBoundary>
<ActivityFeed />
</ErrorBoundary>
<Header />
{/* Spacer to prevent navbar overlap */}
<div className="h-24 md:h-32" aria-hidden="true"></div>
<main className="relative">
<Hero />
{/* Wavy Separator 1 - Hero to About */}
<div className="relative h-24 overflow-hidden">
<svg
className="absolute inset-0 w-full h-full"
viewBox="0 0 1440 120"
preserveAspectRatio="none"
>
<motion.path
d="M0,64 C240,96 480,32 720,64 C960,96 1200,32 1440,64 L1440,120 L0,120 Z"
fill="url(#gradient1)"
initial={{ opacity: 0 }}
animate={{
opacity: 1,
d: [
"M0,64 C240,96 480,32 720,64 C960,96 1200,32 1440,64 L1440,120 L0,120 Z",
"M0,32 C240,64 480,96 720,32 C960,64 1200,96 1440,32 L1440,120 L0,120 Z",
"M0,64 C240,96 480,32 720,64 C960,96 1200,32 1440,64 L1440,120 L0,120 Z",
],
}}
transition={{
opacity: { duration: 0.8, delay: 0.3 },
d: {
duration: 12,
repeat: Infinity,
ease: "easeInOut",
},
}}
/>
<defs>
<linearGradient id="gradient1" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" stopColor="#BAE6FD" stopOpacity="0.4" />
<stop offset="50%" stopColor="#DDD6FE" stopOpacity="0.4" />
<stop offset="100%" stopColor="#FBCFE8" stopOpacity="0.4" />
</linearGradient>
</defs>
</svg>
</div>
<About />
{/* Wavy Separator 2 - About to Projects */}
<div className="relative h-24 overflow-hidden">
<svg
className="absolute inset-0 w-full h-full"
viewBox="0 0 1440 120"
preserveAspectRatio="none"
>
<motion.path
d="M0,32 C240,64 480,96 720,32 C960,64 1200,96 1440,32 L1440,120 L0,120 Z"
fill="url(#gradient2)"
initial={{ opacity: 0 }}
animate={{
opacity: 1,
d: [
"M0,32 C240,64 480,96 720,32 C960,64 1200,96 1440,32 L1440,120 L0,120 Z",
"M0,96 C240,32 480,64 720,96 C960,32 1200,64 1440,96 L1440,120 L0,120 Z",
"M0,32 C240,64 480,96 720,32 C960,64 1200,96 1440,32 L1440,120 L0,120 Z",
],
}}
transition={{
opacity: { duration: 0.8, delay: 0.3 },
d: {
duration: 14,
repeat: Infinity,
ease: "easeInOut",
},
}}
/>
<defs>
<linearGradient id="gradient2" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" stopColor="#FED7AA" stopOpacity="0.4" />
<stop offset="50%" stopColor="#FDE68A" stopOpacity="0.4" />
<stop offset="100%" stopColor="#FCA5A5" stopOpacity="0.4" />
</linearGradient>
</defs>
</svg>
</div>
<Projects />
{/* Wavy Separator 3 - Projects to Contact */}
<div className="relative h-24 overflow-hidden">
<svg
className="absolute inset-0 w-full h-full"
viewBox="0 0 1440 120"
preserveAspectRatio="none"
>
<motion.path
d="M0,96 C240,32 480,64 720,96 C960,32 1200,64 1440,96 L1440,120 L0,120 Z"
fill="url(#gradient3)"
initial={{ opacity: 0 }}
animate={{
opacity: 1,
d: [
"M0,96 C240,32 480,64 720,96 C960,32 1200,64 1440,96 L1440,120 L0,120 Z",
"M0,64 C240,96 480,32 720,64 C960,96 1200,32 1440,64 L1440,120 L0,120 Z",
"M0,96 C240,32 480,64 720,96 C960,32 1200,64 1440,96 L1440,120 L0,120 Z",
],
}}
transition={{
opacity: { duration: 0.8, delay: 0.3 },
d: {
duration: 16,
repeat: Infinity,
ease: "easeInOut",
},
}}
/>
<defs>
<linearGradient id="gradient3" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" stopColor="#99F6E4" stopOpacity="0.4" />
<stop offset="50%" stopColor="#A7F3D0" stopOpacity="0.4" />
<stop offset="100%" stopColor="#D9F99D" stopOpacity="0.4" />
</linearGradient>
</defs>
</svg>
</div>
<Contact />
</main>
<Footer />
</div>
);
} }

View File

@@ -6,40 +6,8 @@ import { ArrowLeft } from 'lucide-react';
import Header from "../components/Header"; import Header from "../components/Header";
import Footer from "../components/Footer"; import Footer from "../components/Footer";
import Link from "next/link"; import Link from "next/link";
import { useLocale, useTranslations } from "next-intl";
import { useEffect, useState } from "react";
import type { JSONContent } from "@tiptap/react";
import RichTextClient from "../components/RichTextClient";
export default function PrivacyPolicy() { export default function PrivacyPolicy() {
const locale = useLocale();
const t = useTranslations("common");
const [cmsDoc, setCmsDoc] = useState<JSONContent | null>(null);
const [cmsTitle, setCmsTitle] = useState<string | null>(null);
useEffect(() => {
(async () => {
try {
const res = await fetch(
`/api/content/page?key=${encodeURIComponent("privacy-policy")}&locale=${encodeURIComponent(locale)}`,
);
const data = await res.json();
// Only use CMS content if it exists for the active locale.
if (data?.content?.content && data?.content?.locale === locale) {
setCmsDoc(data.content.content as JSONContent);
setCmsTitle((data.content.title as string | null) ?? null);
} else {
setCmsDoc(null);
setCmsTitle(null);
}
} catch {
// ignore; fallback to static content
setCmsDoc(null);
setCmsTitle(null);
}
})();
}, [locale]);
return ( return (
<div className="min-h-screen animated-bg"> <div className="min-h-screen animated-bg">
<Header /> <Header />
@@ -51,15 +19,15 @@ export default function PrivacyPolicy() {
className="mb-8" className="mb-8"
> >
<motion.a <motion.a
href={`/${locale}`} href="/"
className="inline-flex items-center space-x-2 text-blue-400 hover:text-blue-300 transition-colors mb-6" className="inline-flex items-center space-x-2 text-blue-400 hover:text-blue-300 transition-colors mb-6"
> >
<ArrowLeft size={20} /> <ArrowLeft size={20} />
<span>{t("backToHome")}</span> <span>Back to Home</span>
</motion.a> </motion.a>
<h1 className="text-4xl md:text-5xl font-bold mb-6 gradient-text"> <h1 className="text-4xl md:text-5xl font-bold mb-6 gradient-text">
{cmsTitle || "Datenschutzerklärung"} Datenschutzerklärung
</h1> </h1>
</motion.div> </motion.div>
@@ -69,77 +37,59 @@ export default function PrivacyPolicy() {
transition={{ duration: 0.8, delay: 0.2 }} transition={{ duration: 0.8, delay: 0.2 }}
className="glass-card p-8 rounded-2xl space-y-6 text-white" className="glass-card p-8 rounded-2xl space-y-6 text-white"
> >
{cmsDoc ? ( <div className="text-gray-300 leading-relaxed">
<RichTextClient doc={cmsDoc} className="prose prose-invert max-w-none text-gray-300" /> <p>
) : ( Der Schutz Ihrer persönlichen Daten ist mir wichtig. In dieser Datenschutzerklärung informiere ich Sie
<> über die Verarbeitung personenbezogener Daten im Rahmen meines Internet-Angebots.
<div className="text-gray-300 leading-relaxed"> </p>
<p> </div>
Der Schutz Ihrer persönlichen Daten ist mir wichtig. In dieser Datenschutzerklärung informiere ich Sie
über die Verarbeitung personenbezogener Daten im Rahmen meines Internet-Angebots.
</p>
</div>
<div className="text-gray-300 leading-relaxed"> <div className="text-gray-300 leading-relaxed">
<h2 className="text-2xl font-semibold mb-4">Verantwortlicher für die Datenverarbeitung</h2> <h2 className="text-2xl font-semibold mb-4">
<div className="space-y-2 text-gray-300"> Verantwortlicher für die Datenverarbeitung
<p> </h2>
<strong>Name:</strong> Dennis Konkol <div className="space-y-2 text-gray-300">
</p> <p><strong>Name:</strong> Dennis Konkol</p>
<p> <p><strong>Adresse:</strong> Auf dem Ziegenbrink 2B, 49082 Osnabrück, Deutschland</p>
<strong>Adresse:</strong> Auf dem Ziegenbrink 2B, 49082 Osnabrück, Deutschland <p><strong>E-Mail:</strong> <Link className="text-blue-400 hover:text-blue-300 transition-colors" href="mailto:info@dk0.dev">info@dk0.dev</Link></p>
</p> <p><strong>Website:</strong> <Link className="text-blue-400 hover:text-blue-300 transition-colors" href="https://www.dk0.dev">dk0.dev</Link></p>
<p> </div>
<strong>E-Mail:</strong>{" "} <p className="mt-4">
<Link className="text-blue-400 hover:text-blue-300 transition-colors" href="mailto:info@dk0.dev"> Diese Datenschutzerklärung gilt für die Verarbeitung personenbezogener Daten durch den oben genannten Verantwortlichen.
info@dk0.dev </p>
</Link> </div>
</p> <h2 className="text-2xl font-semibold mt-6">
<p> Erfassung allgemeiner Informationen beim Besuch meiner Website
<strong>Website:</strong>{" "} </h2>
<Link className="text-blue-400 hover:text-blue-300 transition-colors" href="https://www.dk0.dev"> <div className="mt-2">
dk0.dev Beim Zugriff auf meiner Website werden automatisch Informationen
</Link> allgemeiner Natur erfasst. Diese beinhalten unter anderem:
</p> <ul className="list-disc list-inside mt-2">
</div> <li>IP-Adresse (in anonymisierter Form)</li>
<p className="mt-4"> <li>Uhrzeit</li>
Diese Datenschutzerklärung gilt für die Verarbeitung personenbezogener Daten durch den oben genannten <li>Browsertyp</li>
Verantwortlichen. <li>Verwendetes Betriebssystem</li>
</p> <li>Referrer-URL (die zuvor besuchte Seite)</li>
</div> </ul>
<br />
<h2 className="text-2xl font-semibold mt-6"> Diese Informationen werden anonymisiert erfasst und dienen
Erfassung allgemeiner Informationen beim Besuch meiner Website ausschließlich statistischen Auswertungen. Rückschlüsse auf Ihre
</h2> Person sind nicht möglich. Diese Daten werden verarbeitet, um:
<div className="mt-2"> <ul className="list-disc list-inside mt-2">
Beim Zugriff auf meiner Website werden automatisch Informationen allgemeiner Natur erfasst. Diese <li>die Inhalte meiner Website korrekt auszuliefern,</li>
beinhalten unter anderem: <li>die Inhalte meiner Website zu optimieren,</li>
<ul className="list-disc list-inside mt-2"> <li>die Systemsicherheit und -stabilität zu analysiern.</li>
<li>IP-Adresse (in anonymisierter Form)</li> </ul>
<li>Uhrzeit</li> </div>
<li>Browsertyp</li> <h2 className="text-2xl font-semibold mt-6">Cookies</h2>
<li>Verwendetes Betriebssystem</li> <p className="mt-2">
<li>Referrer-URL (die zuvor besuchte Seite)</li> Meine Website verwendet keine Cookies. Daher ist kein
</ul> Cookie-Consent-Banner erforderlich.
<br /> </p>
Diese Informationen werden anonymisiert erfasst und dienen ausschließlich statistischen Auswertungen. <h2 className="text-2xl font-semibold mt-6">
Rückschlüsse auf Ihre Person sind nicht möglich. Diese Daten werden verarbeitet, um: Analyse- und Tracking-Tools
<ul className="list-disc list-inside mt-2"> </h2>
<li>die Inhalte meiner Website korrekt auszuliefern,</li> <p className="mt-2">
<li>die Inhalte meiner Website zu optimieren,</li>
<li>die Systemsicherheit und -stabilität zu analysiern.</li>
</ul>
</div>
<h2 className="text-2xl font-semibold mt-6">Cookies</h2>
<p className="mt-2">
Diese Website verwendet ein technisch notwendiges Cookie, um deine Datenschutz-Einstellungen (z.B.
Analytics/Chatbot) zu speichern. Ohne dieses Cookie wäre ein Consent-Banner bei jedem Besuch erneut
nötig.
</p>
<h2 className="text-2xl font-semibold mt-6">Analyse- und Tracking-Tools</h2>
<p className="mt-2">
Die nachfolgend beschriebene Analyse- und Tracking-Methode (im Die nachfolgend beschriebene Analyse- und Tracking-Methode (im
Folgenden Maßnahme genannt) basiert auf Art. 6 Abs. 1 S. 1 lit. f Folgenden Maßnahme genannt) basiert auf Art. 6 Abs. 1 S. 1 lit. f
DSGVO. Durch diese Maßnahme möchten ich eine benutzerfreundliche DSGVO. Durch diese Maßnahme möchten ich eine benutzerfreundliche
@@ -168,11 +118,6 @@ export default function PrivacyPolicy() {
</Link> </Link>
. .
</p> </p>
<p className="mt-4">
Zusätzlich kann diese Website optionale, selbst gehostete
Nutzungsstatistiken erfassen (z.B. Seitenaufrufe, Performance-Metriken),
die erst nach deiner Einwilligung im Consent-Banner aktiviert werden.
</p>
<h2 className="text-2xl font-semibold mt-6">Kontaktformular</h2> <h2 className="text-2xl font-semibold mt-6">Kontaktformular</h2>
<p className="mt-2"> <p className="mt-2">
Wenn Sie das Kontaktformular nutzen, werden Ihre Angaben zur Wenn Sie das Kontaktformular nutzen, werden Ihre Angaben zur
@@ -181,17 +126,6 @@ export default function PrivacyPolicy() {
<br /> <br />
Rechtsgrundlage: Art. 6 Abs. 1 S. 1 lit. a DSGVO (Einwilligung). Rechtsgrundlage: Art. 6 Abs. 1 S. 1 lit. a DSGVO (Einwilligung).
</p> </p>
<h2 className="text-2xl font-semibold mt-6">Chatbot</h2>
<p className="mt-2">
Wenn du den optionalen Chatbot nutzt, werden die von dir eingegebenen
Nachrichten verarbeitet, um eine Antwort zu generieren. Die Verarbeitung
kann dabei über eine selbst gehostete Automations-/Chat-Infrastruktur
(z.B. n8n) erfolgen. Bitte gib im Chat keine sensiblen Daten ein.
<br />
<br />
Rechtsgrundlage: Art. 6 Abs. 1 S. 1 lit. a DSGVO (Einwilligung) der
Chatbot wird erst nach Aktivierung im Consent-Banner geladen.
</p>
<h2 className="text-2xl font-semibold mt-6">Social Media Links</h2> <h2 className="text-2xl font-semibold mt-6">Social Media Links</h2>
<p className="mt-2"> <p className="mt-2">
Unsere Website enthält Links zu GitHub und LinkedIn. Durch das Unsere Website enthält Links zu GitHub und LinkedIn. Durch das
@@ -299,8 +233,6 @@ export default function PrivacyPolicy() {
<div className="pt-4 border-t border-gray-700"> <div className="pt-4 border-t border-gray-700">
<p className="text-gray-400 text-sm">Letzte Aktualisierung: 12.02.2025</p> <p className="text-gray-400 text-sm">Letzte Aktualisierung: 12.02.2025</p>
</div> </div>
</>
)}
</motion.div> </motion.div>
</main> </main>
<Footer /> <Footer />

View File

@@ -6,11 +6,9 @@ import Link from 'next/link';
import { useParams } from 'next/navigation'; import { useParams } from 'next/navigation';
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import ReactMarkdown from 'react-markdown'; import ReactMarkdown from 'react-markdown';
import { useLocale, useTranslations } from "next-intl";
interface Project { interface Project {
id: number; id: number;
slug: string;
title: string; title: string;
description: string; description: string;
content: string; content: string;
@@ -26,8 +24,6 @@ interface Project {
const ProjectDetail = () => { const ProjectDetail = () => {
const params = useParams(); const params = useParams();
const slug = params.slug as string; const slug = params.slug as string;
const locale = useLocale();
const t = useTranslations("common");
const [project, setProject] = useState<Project | null>(null); const [project, setProject] = useState<Project | null>(null);
// Load project from API by slug // Load project from API by slug
@@ -94,11 +90,11 @@ const ProjectDetail = () => {
className="mb-8" className="mb-8"
> >
<Link <Link
href={`/${locale}/projects`} href="/projects"
className="inline-flex items-center space-x-2 text-stone-500 hover:text-stone-900 transition-colors group" className="inline-flex items-center space-x-2 text-stone-500 hover:text-stone-900 transition-colors group"
> >
<ArrowLeft size={20} className="group-hover:-translate-x-1 transition-transform" /> <ArrowLeft size={20} className="group-hover:-translate-x-1 transition-transform" />
<span className="font-medium">{t("backToProjects")}</span> <span className="font-medium">Back to Projects</span>
</Link> </Link>
</motion.div> </motion.div>

View File

@@ -4,11 +4,9 @@ import { useState, useEffect } from "react";
import { motion } from 'framer-motion'; import { motion } from 'framer-motion';
import { ExternalLink, Github, Calendar, ArrowLeft, Search } from 'lucide-react'; import { ExternalLink, Github, Calendar, ArrowLeft, Search } from 'lucide-react';
import Link from 'next/link'; import Link from 'next/link';
import { useLocale, useTranslations } from "next-intl";
interface Project { interface Project {
id: number; id: number;
slug: string;
title: string; title: string;
description: string; description: string;
content: string; content: string;
@@ -28,8 +26,6 @@ const ProjectsPage = () => {
const [selectedCategory, setSelectedCategory] = useState("All"); const [selectedCategory, setSelectedCategory] = useState("All");
const [searchQuery, setSearchQuery] = useState(""); const [searchQuery, setSearchQuery] = useState("");
const [mounted, setMounted] = useState(false); const [mounted, setMounted] = useState(false);
const locale = useLocale();
const t = useTranslations("common");
// Load projects from API // Load projects from API
useEffect(() => { useEffect(() => {
@@ -91,11 +87,11 @@ const ProjectsPage = () => {
className="mb-12" className="mb-12"
> >
<Link <Link
href={`/${locale}`} href="/"
className="inline-flex items-center space-x-2 text-stone-500 hover:text-stone-800 transition-colors mb-8 group" className="inline-flex items-center space-x-2 text-stone-500 hover:text-stone-800 transition-colors mb-8 group"
> >
<ArrowLeft size={20} className="group-hover:-translate-x-1 transition-transform" /> <ArrowLeft size={20} className="group-hover:-translate-x-1 transition-transform" />
<span>{t("backToHome")}</span> <span>Back to Home</span>
</Link> </Link>
<h1 className="text-5xl md:text-6xl font-black font-sans mb-6 text-stone-900 tracking-tight"> <h1 className="text-5xl md:text-6xl font-black font-sans mb-6 text-stone-900 tracking-tight">
@@ -226,7 +222,7 @@ const ProjectsPage = () => {
<div className="p-6 flex flex-col flex-1"> <div className="p-6 flex flex-col flex-1">
{/* Stretched Link covering the whole card (including image area) */} {/* Stretched Link covering the whole card (including image area) */}
<Link <Link
href={`/${locale}/projects/${project.slug}`} href={`/projects/${project.title.toLowerCase().replace(/[^a-z0-9]+/g, '-')}`}
className="absolute inset-0 z-10" className="absolute inset-0 z-10"
aria-label={`View project ${project.title}`} aria-label={`View project ${project.title}`}
/> />

View File

@@ -1,25 +0,0 @@
import { NextResponse } from "next/server";
import { getBaseUrl } from "@/lib/seo";
export const dynamic = "force-dynamic";
export async function GET() {
const base = getBaseUrl();
const body = [
"User-agent: *",
"Allow: /",
"Disallow: /api/",
"Disallow: /manage",
"Disallow: /editor",
`Sitemap: ${base}/sitemap.xml`,
"",
].join("\n");
return new NextResponse(body, {
headers: {
"Content-Type": "text/plain; charset=utf-8",
"Cache-Control": "public, max-age=3600",
},
});
}

View File

@@ -1,20 +1,67 @@
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import { generateSitemapXml, getSitemapEntries } from "@/lib/sitemap";
export const dynamic = "force-dynamic"; export const dynamic = "force-dynamic";
export async function GET() { export async function GET() {
const baseUrl = process.env.NEXT_PUBLIC_BASE_URL;
const apiUrl = `${baseUrl}/api/sitemap`; // Verwende die vollständige URL zur API
// In test runs, allow returning a mocked sitemap explicitly
if (process.env.NODE_ENV === "test" && process.env.GHOST_MOCK_SITEMAP) {
// For tests return a simple object so tests can inspect `.body`
if (process.env.NODE_ENV === "test") {
/* eslint-disable @typescript-eslint/no-explicit-any */
return {
body: process.env.GHOST_MOCK_SITEMAP,
headers: { "Content-Type": "application/xml" },
} as any;
/* eslint-enable @typescript-eslint/no-explicit-any */
}
return new NextResponse(process.env.GHOST_MOCK_SITEMAP, {
headers: { "Content-Type": "application/xml" },
});
}
try { try {
const entries = await getSitemapEntries(); // Holt die Sitemap-Daten von der API
const xml = generateSitemapXml(entries); // Try global fetch first, then fall back to node-fetch
/* eslint-disable @typescript-eslint/no-explicit-any */
let res: any;
try {
if (typeof (globalThis as any).fetch === "function") {
res = await (globalThis as any).fetch(apiUrl);
}
} catch (_e) {
res = undefined;
}
if (!res || typeof res.ok === "undefined" || !res.ok) {
try {
const mod = await import("node-fetch");
const nodeFetch = (mod as any).default ?? mod;
res = await (nodeFetch as any)(apiUrl);
} catch (err) {
console.error("Error fetching sitemap:", err);
return new NextResponse("Error fetching sitemap", { status: 500 });
}
}
/* eslint-enable @typescript-eslint/no-explicit-any */
if (!res || !res.ok) {
console.error(
`Failed to fetch sitemap: ${res?.statusText ?? "no response"}`,
);
return new NextResponse("Failed to fetch sitemap", { status: 500 });
}
const xml = await res.text();
// Gibt die XML mit dem richtigen Content-Type zurück
return new NextResponse(xml, { return new NextResponse(xml, {
headers: { "Content-Type": "application/xml" }, headers: { "Content-Type": "application/xml" },
}); });
} catch (error) { } catch (error) {
console.error("Error generating sitemap.xml:", error); console.error("Error fetching sitemap:", error);
// Always return a valid sitemap with 200 so crawlers don't treat it as broken. return new NextResponse("Error fetching sitemap", { status: 500 });
return new NextResponse(generateSitemapXml([]), {
headers: { "Content-Type": "application/xml" },
});
} }
} }

View File

@@ -72,16 +72,15 @@ export function AnalyticsDashboard({ isAuthenticated }: AnalyticsDashboardProps)
try { try {
setLoading(true); setLoading(true);
setError(null); setError(null);
const sessionToken = sessionStorage.getItem('admin_session_token') || '';
// Add cache-busting parameter to ensure fresh data after reset // Add cache-busting parameter to ensure fresh data after reset
const cacheBust = `?nocache=true&t=${Date.now()}`; const cacheBust = `?nocache=true&t=${Date.now()}`;
const [analyticsRes, performanceRes] = await Promise.all([ const [analyticsRes, performanceRes] = await Promise.all([
fetch(`/api/analytics/dashboard${cacheBust}`, { fetch(`/api/analytics/dashboard${cacheBust}`, {
headers: { 'x-admin-request': 'true', 'x-session-token': sessionToken } headers: { 'x-admin-request': 'true' }
}), }),
fetch(`/api/analytics/performance${cacheBust}`, { fetch(`/api/analytics/performance${cacheBust}`, {
headers: { 'x-admin-request': 'true', 'x-session-token': sessionToken } headers: { 'x-admin-request': 'true' }
}) })
]); ]);
@@ -129,13 +128,11 @@ export function AnalyticsDashboard({ isAuthenticated }: AnalyticsDashboardProps)
setResetting(true); setResetting(true);
setError(null); setError(null);
try { try {
const sessionToken = sessionStorage.getItem('admin_session_token') || '';
const response = await fetch('/api/analytics/reset', { const response = await fetch('/api/analytics/reset', {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'x-admin-request': 'true', 'x-admin-request': 'true'
'x-session-token': sessionToken
}, },
body: JSON.stringify({ type: resetType }) body: JSON.stringify({ type: resetType })
}); });

View File

@@ -69,10 +69,6 @@ export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }
// Track performance metrics to our API // Track performance metrics to our API
const trackPerformanceToAPI = async () => { const trackPerformanceToAPI = async () => {
try { try {
if (typeof performance === "undefined" || typeof performance.getEntriesByType !== "function") {
return;
}
// Get current page path to extract project ID if on project page // Get current page path to extract project ID if on project page
const path = window.location.pathname; const path = window.location.pathname;
const projectMatch = path.match(/\/projects\/([^\/]+)/); const projectMatch = path.match(/\/projects\/([^\/]+)/);
@@ -193,7 +189,6 @@ export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }
// Track scroll depth // Track scroll depth
let maxScrollDepth = 0; let maxScrollDepth = 0;
const firedScrollMilestones = new Set<number>();
const handleScroll = () => { const handleScroll = () => {
try { try {
if (typeof window === 'undefined' || typeof document === 'undefined') return; if (typeof window === 'undefined' || typeof document === 'undefined') return;
@@ -207,14 +202,18 @@ export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }
(window.scrollY / (scrollHeight - innerHeight)) * 100 (window.scrollY / (scrollHeight - innerHeight)) * 100
); );
if (scrollDepth > maxScrollDepth) maxScrollDepth = scrollDepth; if (scrollDepth > maxScrollDepth) {
maxScrollDepth = scrollDepth;
// Track each milestone once (avoid spamming events on every scroll tick)
const milestones = [25, 50, 75, 90]; // Track scroll milestones
for (const milestone of milestones) { if (scrollDepth >= 25 && scrollDepth < 50 && maxScrollDepth >= 25) {
if (maxScrollDepth >= milestone && !firedScrollMilestones.has(milestone)) { trackEvent('scroll-depth', { depth: 25, url: window.location.pathname });
firedScrollMilestones.add(milestone); } else if (scrollDepth >= 50 && scrollDepth < 75 && maxScrollDepth >= 50) {
trackEvent('scroll-depth', { depth: milestone, url: window.location.pathname }); trackEvent('scroll-depth', { depth: 50, url: window.location.pathname });
} else if (scrollDepth >= 75 && scrollDepth < 90 && maxScrollDepth >= 75) {
trackEvent('scroll-depth', { depth: 75, url: window.location.pathname });
} else if (scrollDepth >= 90 && maxScrollDepth >= 90) {
trackEvent('scroll-depth', { depth: 90, url: window.location.pathname });
} }
} }
} catch (error) { } catch (error) {
@@ -270,8 +269,6 @@ export const AnalyticsProvider: React.FC<AnalyticsProviderProps> = ({ children }
// Cleanup // Cleanup
return () => { return () => {
try { try {
// Remove load handler if we added it
window.removeEventListener('load', trackPerformanceToAPI);
window.removeEventListener('popstate', handleRouteChange); window.removeEventListener('popstate', handleRouteChange);
document.removeEventListener('click', handleClick); document.removeEventListener('click', handleClick);
document.removeEventListener('submit', handleSubmit); document.removeEventListener('submit', handleSubmit);

View File

@@ -1,414 +0,0 @@
'use client';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { EditorContent, useEditor, type JSONContent } from '@tiptap/react';
import StarterKit from '@tiptap/starter-kit';
import Underline from '@tiptap/extension-underline';
import Link from '@tiptap/extension-link';
import { TextStyle } from '@tiptap/extension-text-style';
import Color from '@tiptap/extension-color';
import Highlight from '@tiptap/extension-highlight';
import { Bold, Italic, Underline as UnderlineIcon, List, ListOrdered, Link as LinkIcon, Highlighter, Type, Save, RefreshCw } from 'lucide-react';
import { FontFamily, type AllowedFontFamily } from '@/lib/tiptap/fontFamily';
const EMPTY_DOC: JSONContent = {
type: 'doc',
content: [{ type: 'paragraph', content: [{ type: 'text', text: '' }] }],
};
type PageListItem = {
id: number;
key: string;
translations: Array<{ locale: string; updatedAt: string; title: string | null; slug: string | null }>;
};
export default function ContentManager() {
const [pages, setPages] = useState<PageListItem[]>([]);
const [selectedKey, setSelectedKey] = useState<string>('privacy-policy');
const [selectedLocale, setSelectedLocale] = useState<string>('de');
const [title, setTitle] = useState<string>('');
const [slug, setSlug] = useState<string>('');
const [isLoading, setIsLoading] = useState<boolean>(true);
const [isSaving, setIsSaving] = useState<boolean>(false);
const [error, setError] = useState<string>('');
const [fontFamily, setFontFamily] = useState<AllowedFontFamily | ''>('');
const [color, setColor] = useState<string>('#111827');
const extensions = useMemo(
() => [
StarterKit,
Underline,
Link.configure({
openOnClick: false,
HTMLAttributes: { rel: 'noopener noreferrer', target: '_blank' },
}),
TextStyle,
FontFamily,
Color,
Highlight,
],
[],
);
const editor = useEditor({
extensions,
content: EMPTY_DOC,
editorProps: {
attributes: {
class:
'prose prose-stone max-w-none focus:outline-none min-h-[320px] p-4 bg-white rounded-xl border border-stone-200',
},
},
});
const sessionHeaders = () => {
const sessionToken = sessionStorage.getItem('admin_session_token') || '';
return {
'x-admin-request': 'true',
'x-session-token': sessionToken,
'Content-Type': 'application/json',
};
};
const loadPages = useCallback(async () => {
setError('');
try {
setIsLoading(true);
const res = await fetch('/api/content/pages', { headers: sessionHeaders() });
const data = await res.json();
if (!res.ok) throw new Error(data?.error || 'Failed to load content pages');
setPages(data.pages || []);
} catch (e) {
setError(e instanceof Error ? e.message : 'Failed to load content pages');
} finally {
setIsLoading(false);
}
}, []);
const loadSelected = useCallback(async () => {
if (!editor) return;
setError('');
try {
setIsLoading(true);
const res = await fetch(`/api/content/page?key=${encodeURIComponent(selectedKey)}&locale=${encodeURIComponent(selectedLocale)}`);
const data = await res.json();
const translation = data?.content;
const nextTitle = (translation?.title as string | undefined) || '';
const nextSlug = (translation?.slug as string | undefined) || '';
const nextDoc = (translation?.content as JSONContent | undefined) || EMPTY_DOC;
setTitle(nextTitle);
setSlug(nextSlug);
editor.commands.setContent(nextDoc);
setFontFamily('');
} catch (e) {
setError(e instanceof Error ? e.message : 'Failed to load content');
} finally {
setIsLoading(false);
}
}, [editor, selectedKey, selectedLocale]);
useEffect(() => {
loadPages();
}, [loadPages]);
useEffect(() => {
loadSelected();
}, [loadSelected]);
const handleSave = async () => {
if (!editor) return;
setError('');
try {
setIsSaving(true);
const content = editor.getJSON();
const res = await fetch('/api/content/pages', {
method: 'POST',
headers: sessionHeaders(),
body: JSON.stringify({
key: selectedKey,
locale: selectedLocale,
title: title || null,
slug: slug || null,
content,
}),
});
const data = await res.json();
if (!res.ok) throw new Error(data?.error || 'Failed to save content');
await loadPages();
} catch (e) {
setError(e instanceof Error ? e.message : 'Failed to save content');
} finally {
setIsSaving(false);
}
};
const localeOptions = ['en', 'de'];
const fontOptions: Array<{ label: string; value: AllowedFontFamily | '' }> = [
{ label: 'Default', value: '' },
{ label: 'Inter', value: 'Inter' },
{ label: 'Sans', value: 'ui-sans-serif' },
{ label: 'Serif', value: 'ui-serif' },
{ label: 'Mono', value: 'ui-monospace' },
];
const selectedInfo = useMemo(() => {
const page = pages.find((p) => p.key === selectedKey);
const tr = page?.translations?.find((t) => t.locale === selectedLocale);
return tr;
}, [pages, selectedKey, selectedLocale]);
return (
<div className="space-y-6">
<div className="flex items-start justify-between gap-4">
<div>
<h2 className="text-2xl font-bold text-stone-900">Content Manager</h2>
<p className="text-stone-500 mt-1">
Edit texts/pages with rich formatting (bold, underline, links, highlights).
</p>
</div>
<button
onClick={loadPages}
className="flex items-center gap-2 px-4 py-2 bg-stone-100 text-stone-700 rounded-lg hover:bg-stone-200 transition-colors"
>
<RefreshCw className="w-4 h-4" />
<span>Refresh</span>
</button>
</div>
{error && (
<div className="p-4 bg-red-50 border border-red-100 rounded-xl text-red-700 text-sm">
{error}
</div>
)}
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
<div className="lg:col-span-1 space-y-4">
<div className="bg-white border border-stone-200 rounded-xl p-4 space-y-3">
<div>
<label className="block text-sm font-medium text-stone-700 mb-1">Page key</label>
<select
value={selectedKey}
onChange={(e) => setSelectedKey(e.target.value)}
className="w-full px-3 py-2 bg-white border border-stone-200 rounded-lg text-stone-900 focus:outline-none focus:ring-2 focus:ring-stone-300"
>
{pages.map((p) => (
<option key={p.key} value={p.key}>
{p.key}
</option>
))}
{pages.length === 0 && (
<>
<option value="privacy-policy">privacy-policy</option>
<option value="legal-notice">legal-notice</option>
<option value="home-hero">home-hero</option>
</>
)}
</select>
</div>
<div>
<label className="block text-sm font-medium text-stone-700 mb-1">Locale</label>
<select
value={selectedLocale}
onChange={(e) => setSelectedLocale(e.target.value)}
className="w-full px-3 py-2 bg-white border border-stone-200 rounded-lg text-stone-900 focus:outline-none focus:ring-2 focus:ring-stone-300"
>
{localeOptions.map((l) => (
<option key={l} value={l}>
{l}
</option>
))}
</select>
</div>
<div className="text-xs text-stone-500">
Last updated:{' '}
<span className="font-medium text-stone-700">
{selectedInfo?.updatedAt ? new Date(selectedInfo.updatedAt).toLocaleString() : '—'}
</span>
</div>
</div>
<div className="bg-white border border-stone-200 rounded-xl p-4 space-y-3">
<div>
<label className="block text-sm font-medium text-stone-700 mb-1">Title (optional)</label>
<input
value={title}
onChange={(e) => setTitle(e.target.value)}
className="w-full px-3 py-2 bg-white border border-stone-200 rounded-lg text-stone-900 focus:outline-none focus:ring-2 focus:ring-stone-300"
placeholder="Page title"
/>
</div>
<div>
<label className="block text-sm font-medium text-stone-700 mb-1">Slug (optional)</label>
<input
value={slug}
onChange={(e) => setSlug(e.target.value)}
className="w-full px-3 py-2 bg-white border border-stone-200 rounded-lg text-stone-900 focus:outline-none focus:ring-2 focus:ring-stone-300"
placeholder="privacy-policy"
/>
</div>
<button
onClick={handleSave}
disabled={isSaving || isLoading || !editor}
className="w-full flex items-center justify-center gap-2 px-4 py-2 bg-stone-900 text-stone-50 rounded-lg hover:bg-stone-800 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
>
<Save className="w-4 h-4" />
<span>{isSaving ? 'Saving…' : 'Save'}</span>
</button>
</div>
</div>
<div className="lg:col-span-2">
<div className="bg-white border border-stone-200 rounded-xl p-4">
<div className="text-sm font-semibold text-stone-900 mb-3">Content</div>
{isLoading ? (
<div className="text-stone-500 text-sm">Loading</div>
) : (
<>
{editor && (
<div className="flex flex-wrap items-center gap-2 mb-3">
<button
type="button"
onClick={() => editor.chain().focus().toggleBold().run()}
className={`p-2 rounded-lg border transition-colors ${
editor.isActive('bold')
? 'bg-stone-900 text-stone-50 border-stone-900'
: 'bg-white text-stone-700 border-stone-200 hover:bg-stone-50'
}`}
title="Bold"
>
<Bold className="w-4 h-4" />
</button>
<button
type="button"
onClick={() => editor.chain().focus().toggleItalic().run()}
className={`p-2 rounded-lg border transition-colors ${
editor.isActive('italic')
? 'bg-stone-900 text-stone-50 border-stone-900'
: 'bg-white text-stone-700 border-stone-200 hover:bg-stone-50'
}`}
title="Italic"
>
<Italic className="w-4 h-4" />
</button>
<button
type="button"
onClick={() => editor.chain().focus().toggleUnderline().run()}
className={`p-2 rounded-lg border transition-colors ${
editor.isActive('underline')
? 'bg-stone-900 text-stone-50 border-stone-900'
: 'bg-white text-stone-700 border-stone-200 hover:bg-stone-50'
}`}
title="Underline"
>
<UnderlineIcon className="w-4 h-4" />
</button>
<button
type="button"
onClick={() => editor.chain().focus().toggleHighlight().run()}
className={`p-2 rounded-lg border transition-colors ${
editor.isActive('highlight')
? 'bg-stone-900 text-stone-50 border-stone-900'
: 'bg-white text-stone-700 border-stone-200 hover:bg-stone-50'
}`}
title="Highlight"
>
<Highlighter className="w-4 h-4" />
</button>
<button
type="button"
onClick={() => editor.chain().focus().toggleBulletList().run()}
className={`p-2 rounded-lg border transition-colors ${
editor.isActive('bulletList')
? 'bg-stone-900 text-stone-50 border-stone-900'
: 'bg-white text-stone-700 border-stone-200 hover:bg-stone-50'
}`}
title="Bullet list"
>
<List className="w-4 h-4" />
</button>
<button
type="button"
onClick={() => editor.chain().focus().toggleOrderedList().run()}
className={`p-2 rounded-lg border transition-colors ${
editor.isActive('orderedList')
? 'bg-stone-900 text-stone-50 border-stone-900'
: 'bg-white text-stone-700 border-stone-200 hover:bg-stone-50'
}`}
title="Ordered list"
>
<ListOrdered className="w-4 h-4" />
</button>
<button
type="button"
onClick={() => {
const prev = editor.getAttributes('link')?.href as string | undefined;
const href = prompt('Enter URL', prev || 'https://');
if (!href) return;
editor.chain().focus().extendMarkRange('link').setLink({ href }).run();
}}
className={`p-2 rounded-lg border transition-colors ${
editor.isActive('link')
? 'bg-stone-900 text-stone-50 border-stone-900'
: 'bg-white text-stone-700 border-stone-200 hover:bg-stone-50'
}`}
title="Link"
>
<LinkIcon className="w-4 h-4" />
</button>
<div className="flex items-center gap-2 ml-auto">
<Type className="w-4 h-4 text-stone-500" />
<select
value={fontFamily}
onChange={(e) => {
const next = e.target.value as AllowedFontFamily | '';
setFontFamily(next);
if (!next) {
editor.chain().focus().unsetFontFamily().run();
} else {
editor.chain().focus().setFontFamily(next).run();
}
}}
className="px-3 py-2 bg-white border border-stone-200 rounded-lg text-stone-900 focus:outline-none focus:ring-2 focus:ring-stone-300 text-sm"
title="Font family"
>
{fontOptions.map((f) => (
<option key={f.label} value={f.value}>
{f.label}
</option>
))}
</select>
<input
type="color"
value={color}
onChange={(e) => {
const next = e.target.value;
setColor(next);
editor.chain().focus().setColor(next).run();
}}
className="w-10 h-10 p-1 bg-white border border-stone-200 rounded-lg"
title="Text color"
/>
</div>
</div>
)}
<EditorContent editor={editor} />
</>
)}
<p className="text-xs text-stone-500 mt-3">
Tip: Use bold/underline, links, lists, headings. (Email-safe rendering is handled separately.)
</p>
</div>
</div>
</div>
</div>
);
}

View File

@@ -42,11 +42,9 @@ export const EmailManager: React.FC = () => {
const loadMessages = async () => { const loadMessages = async () => {
try { try {
setIsLoading(true); setIsLoading(true);
const sessionToken = sessionStorage.getItem('admin_session_token') || '';
const response = await fetch('/api/contacts', { const response = await fetch('/api/contacts', {
headers: { headers: {
'x-admin-request': 'true', 'x-admin-request': 'true'
'x-session-token': sessionToken
} }
}); });
@@ -102,13 +100,10 @@ export const EmailManager: React.FC = () => {
if (!selectedMessage || !replyContent.trim()) return; if (!selectedMessage || !replyContent.trim()) return;
try { try {
const sessionToken = sessionStorage.getItem('admin_session_token') || '';
const response = await fetch('/api/email/respond', { const response = await fetch('/api/email/respond', {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'x-admin-request': 'true',
'x-session-token': sessionToken,
}, },
body: JSON.stringify({ body: JSON.stringify({
to: selectedMessage.email, to: selectedMessage.email,
@@ -120,24 +115,6 @@ export const EmailManager: React.FC = () => {
}); });
if (response.ok) { if (response.ok) {
// Persist responded status in DB
try {
await fetch(`/api/contacts/${selectedMessage.id}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'x-admin-request': 'true',
'x-session-token': sessionToken,
},
body: JSON.stringify({
responded: true,
responseTemplate: 'reply',
}),
});
} catch {
// ignore persistence failures
}
setMessages(prev => prev.map(msg => setMessages(prev => prev.map(msg =>
msg.id === selectedMessage.id ? { ...msg, responded: true } : msg msg.id === selectedMessage.id ? { ...msg, responded: true } : msg
)); ));

View File

@@ -23,20 +23,14 @@ export default function ImportExport() {
const handleExport = async () => { const handleExport = async () => {
setIsExporting(true); setIsExporting(true);
try { try {
const sessionToken = sessionStorage.getItem('admin_session_token') || ''; const response = await fetch('/api/projects/export');
const response = await fetch('/api/projects/export', {
headers: {
'x-admin-request': 'true',
'x-session-token': sessionToken,
}
});
if (!response.ok) throw new Error('Export failed'); if (!response.ok) throw new Error('Export failed');
const blob = await response.blob(); const blob = await response.blob();
const url = window.URL.createObjectURL(blob); const url = window.URL.createObjectURL(blob);
const a = document.createElement('a'); const a = document.createElement('a');
a.href = url; a.href = url;
a.download = `portfolio-backup-${new Date().toISOString().split('T')[0]}.json`; a.download = `portfolio-projects-${new Date().toISOString().split('T')[0]}.json`;
document.body.appendChild(a); document.body.appendChild(a);
a.click(); a.click();
window.URL.revokeObjectURL(url); window.URL.revokeObjectURL(url);
@@ -69,14 +63,9 @@ export default function ImportExport() {
const text = await file.text(); const text = await file.text();
const data = JSON.parse(text); const data = JSON.parse(text);
const sessionToken = sessionStorage.getItem('admin_session_token') || '';
const response = await fetch('/api/projects/import', { const response = await fetch('/api/projects/import', {
method: 'POST', method: 'POST',
headers: { headers: { 'Content-Type': 'application/json' },
'Content-Type': 'application/json',
'x-admin-request': 'true',
'x-session-token': sessionToken,
},
body: JSON.stringify(data) body: JSON.stringify(data)
}); });
@@ -119,9 +108,9 @@ export default function ImportExport() {
<div className="space-y-4"> <div className="space-y-4">
{/* Export Section */} {/* Export Section */}
<div className="bg-stone-50 border border-stone-200 rounded-xl p-4"> <div className="bg-stone-50 border border-stone-200 rounded-xl p-4">
<h4 className="font-medium text-stone-900 mb-2">Backup Export (Projekte + CMS)</h4> <h4 className="font-medium text-stone-900 mb-2">Export Projekte</h4>
<p className="text-sm text-stone-600 mb-3"> <p className="text-sm text-stone-600 mb-3">
Vollständiges Backup als JSON herunterladen (inkl. CMS Inhalte und Übersetzungen) Alle Projekte als JSON-Datei herunterladen
</p> </p>
<button <button
onClick={handleExport} onClick={handleExport}
@@ -135,9 +124,9 @@ export default function ImportExport() {
{/* Import Section */} {/* Import Section */}
<div className="bg-stone-50 border border-stone-200 rounded-xl p-4"> <div className="bg-stone-50 border border-stone-200 rounded-xl p-4">
<h4 className="font-medium text-stone-900 mb-2">Backup Import</h4> <h4 className="font-medium text-stone-900 mb-2">Import Projekte</h4>
<p className="text-sm text-stone-600 mb-3"> <p className="text-sm text-stone-600 mb-3">
JSON-Datei mit Backup hochladen (Projekte + CMS + Übersetzungen) JSON-Datei mit Projekten hochladen
</p> </p>
<label className="flex items-center px-4 py-2 bg-stone-900 text-white rounded-lg hover:bg-stone-800 transition-colors cursor-pointer w-fit"> <label className="flex items-center px-4 py-2 bg-stone-900 text-white rounded-lg hover:bg-stone-800 transition-colors cursor-pointer w-fit">
<Upload className="w-4 h-4 mr-2" /> <Upload className="w-4 h-4 mr-2" />

View File

@@ -17,28 +17,10 @@ import {
X X
} from 'lucide-react'; } from 'lucide-react';
import Link from 'next/link'; import Link from 'next/link';
import dynamic from 'next/dynamic'; import { EmailManager } from './EmailManager';
import { AnalyticsDashboard } from './AnalyticsDashboard';
const EmailManager = dynamic( import ImportExport from './ImportExport';
() => import('./EmailManager').then((m) => m.EmailManager), import { ProjectManager } from './ProjectManager';
{ ssr: false, loading: () => <div className="p-6 text-stone-500">Loading emails</div> }
);
const AnalyticsDashboard = dynamic(
() => import('./AnalyticsDashboard').then((m) => m.default),
{ ssr: false, loading: () => <div className="p-6 text-stone-500">Loading analytics</div> }
);
const ImportExport = dynamic(
() => import('./ImportExport').then((m) => m.default),
{ ssr: false, loading: () => <div className="p-6 text-stone-500">Loading tools</div> }
);
const ProjectManager = dynamic(
() => import('./ProjectManager').then((m) => m.ProjectManager),
{ ssr: false, loading: () => <div className="p-6 text-stone-500">Loading projects</div> }
);
const ContentManager = dynamic(
() => import('./ContentManager').then((m) => m.default),
{ ssr: false, loading: () => <div className="p-6 text-stone-500">Loading content</div> }
);
interface Project { interface Project {
id: string; id: string;
@@ -70,7 +52,7 @@ interface ModernAdminDashboardProps {
} }
const ModernAdminDashboard: React.FC<ModernAdminDashboardProps> = ({ isAuthenticated = true }) => { const ModernAdminDashboard: React.FC<ModernAdminDashboardProps> = ({ isAuthenticated = true }) => {
const [activeTab, setActiveTab] = useState<'overview' | 'projects' | 'emails' | 'analytics' | 'content' | 'settings'>('overview'); const [activeTab, setActiveTab] = useState<'overview' | 'projects' | 'emails' | 'analytics' | 'settings'>('overview');
const [projects, setProjects] = useState<Project[]>([]); const [projects, setProjects] = useState<Project[]>([]);
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
@@ -196,31 +178,15 @@ const ModernAdminDashboard: React.FC<ModernAdminDashboardProps> = ({ isAuthentic
}; };
useEffect(() => { useEffect(() => {
// Prioritize the data needed for the initial dashboard render // Load all data (authentication disabled)
void (async () => { loadAllData();
await Promise.all([loadProjects(), loadSystemStats()]); }, [loadAllData]);
const idle = (cb: () => void) => {
if (typeof window !== 'undefined' && 'requestIdleCallback' in window) {
(window as unknown as { requestIdleCallback: (fn: () => void) => void }).requestIdleCallback(cb);
} else {
setTimeout(cb, 300);
}
};
idle(() => {
void loadAnalytics();
void loadEmails();
});
})();
}, [loadProjects, loadSystemStats, loadAnalytics, loadEmails]);
const navigation = [ const navigation = [
{ id: 'overview', label: 'Dashboard', icon: Home, color: 'blue', description: 'Overview & Statistics' }, { id: 'overview', label: 'Dashboard', icon: Home, color: 'blue', description: 'Overview & Statistics' },
{ id: 'projects', label: 'Projects', icon: Database, color: 'green', description: 'Manage Projects' }, { id: 'projects', label: 'Projects', icon: Database, color: 'green', description: 'Manage Projects' },
{ id: 'emails', label: 'Emails', icon: Mail, color: 'purple', description: 'Email Management' }, { id: 'emails', label: 'Emails', icon: Mail, color: 'purple', description: 'Email Management' },
{ id: 'analytics', label: 'Analytics', icon: Activity, color: 'orange', description: 'Site Analytics' }, { id: 'analytics', label: 'Analytics', icon: Activity, color: 'orange', description: 'Site Analytics' },
{ id: 'content', label: 'Content', icon: Shield, color: 'teal', description: 'Texts, pages & localization' },
{ id: 'settings', label: 'Settings', icon: Settings, color: 'gray', description: 'System Settings' } { id: 'settings', label: 'Settings', icon: Settings, color: 'gray', description: 'System Settings' }
]; ];
@@ -255,7 +221,7 @@ const ModernAdminDashboard: React.FC<ModernAdminDashboardProps> = ({ isAuthentic
{navigation.map((item) => ( {navigation.map((item) => (
<button <button
key={item.id} key={item.id}
onClick={() => setActiveTab(item.id as 'overview' | 'projects' | 'emails' | 'analytics' | 'content' | 'settings')} onClick={() => setActiveTab(item.id as 'overview' | 'projects' | 'emails' | 'analytics' | 'settings')}
className={`flex items-center space-x-2 px-4 py-2 rounded-lg transition-all duration-200 ${ className={`flex items-center space-x-2 px-4 py-2 rounded-lg transition-all duration-200 ${
activeTab === item.id activeTab === item.id
? 'bg-stone-100 text-stone-900 font-medium shadow-sm border border-stone-200' ? 'bg-stone-100 text-stone-900 font-medium shadow-sm border border-stone-200'
@@ -319,7 +285,7 @@ const ModernAdminDashboard: React.FC<ModernAdminDashboardProps> = ({ isAuthentic
<button <button
key={item.id} key={item.id}
onClick={() => { onClick={() => {
setActiveTab(item.id as 'overview' | 'projects' | 'emails' | 'analytics' | 'content' | 'settings'); setActiveTab(item.id as 'overview' | 'projects' | 'emails' | 'analytics' | 'settings');
setMobileMenuOpen(false); setMobileMenuOpen(false);
}} }}
className={`w-full flex items-center space-x-3 px-4 py-3 rounded-lg transition-all duration-200 ${ className={`w-full flex items-center space-x-3 px-4 py-3 rounded-lg transition-all duration-200 ${
@@ -624,10 +590,6 @@ const ModernAdminDashboard: React.FC<ModernAdminDashboardProps> = ({ isAuthentic
<AnalyticsDashboard isAuthenticated={isAuthenticated} /> <AnalyticsDashboard isAuthenticated={isAuthenticated} />
)} )}
{activeTab === 'content' && (
<ContentManager />
)}
{activeTab === 'settings' && ( {activeTab === 'settings' && (
<div className="space-y-8"> <div className="space-y-8">
<div> <div>

View File

@@ -80,12 +80,10 @@ export const ProjectManager: React.FC<ProjectManagerProps> = ({
if (!confirm('Are you sure you want to delete this project?')) return; if (!confirm('Are you sure you want to delete this project?')) return;
try { try {
const sessionToken = sessionStorage.getItem('admin_session_token') || '';
await fetch(`/api/projects/${projectId}`, { await fetch(`/api/projects/${projectId}`, {
method: 'DELETE', method: 'DELETE',
headers: { headers: {
'x-admin-request': 'true', 'x-admin-request': 'true'
'x-session-token': sessionToken
} }
}); });
onProjectsChange(); onProjectsChange();

View File

@@ -1,17 +1,19 @@
services: services:
# PostgreSQL Database # PostgreSQL Database (ARM64 optimized)
postgres: postgres:
image: postgres:15-alpine image: postgres:15-alpine
platform: linux/arm64
container_name: portfolio_postgres_dev container_name: portfolio_postgres_dev
environment: environment:
POSTGRES_DB: portfolio_dev POSTGRES_DB: portfolio_dev
POSTGRES_USER: portfolio_user POSTGRES_USER: portfolio_user
POSTGRES_PASSWORD: portfolio_dev_pass POSTGRES_PASSWORD: portfolio_dev_pass
# POSTGRES_HOST_AUTH_METHOD removed - using default password authentication (more secure) POSTGRES_HOST_AUTH_METHOD: trust
ports:
- "5432:5432"
volumes: volumes:
- postgres_dev_data:/var/lib/postgresql/data - postgres_dev_data:/var/lib/postgresql/data
# init-db.sql mount removed - database is initialized via POSTGRES_DB/POSTGRES_USER - ./scripts/init-db.sql:/docker-entrypoint-initdb.d/init-db.sql
# Additional grants can be done via Prisma migrations if needed
networks: networks:
- portfolio_dev - portfolio_dev
healthcheck: healthcheck:
@@ -20,10 +22,13 @@ services:
timeout: 5s timeout: 5s
retries: 5 retries: 5
# Redis for caching # Redis for caching (ARM64 optimized)
redis: redis:
image: redis:7-alpine image: redis:7-alpine
platform: linux/arm64
container_name: portfolio_redis_dev container_name: portfolio_redis_dev
ports:
- "6379:6379"
volumes: volumes:
- redis_dev_data:/data - redis_dev_data:/data
networks: networks:

View File

@@ -18,9 +18,6 @@ services:
- MY_PASSWORD=${MY_PASSWORD} - MY_PASSWORD=${MY_PASSWORD}
- MY_INFO_PASSWORD=${MY_INFO_PASSWORD} - MY_INFO_PASSWORD=${MY_INFO_PASSWORD}
- ADMIN_BASIC_AUTH=${ADMIN_BASIC_AUTH:-admin:your_secure_password_here} - ADMIN_BASIC_AUTH=${ADMIN_BASIC_AUTH:-admin:your_secure_password_here}
- ADMIN_SESSION_SECRET=${ADMIN_SESSION_SECRET}
# If you already have an existing DB (pre-migrations), set this to true ONCE to baseline.
- PRISMA_AUTO_BASELINE=${PRISMA_AUTO_BASELINE:-false}
- LOG_LEVEL=info - LOG_LEVEL=info
- N8N_WEBHOOK_URL=${N8N_WEBHOOK_URL:-} - N8N_WEBHOOK_URL=${N8N_WEBHOOK_URL:-}
- N8N_SECRET_TOKEN=${N8N_SECRET_TOKEN:-} - N8N_SECRET_TOKEN=${N8N_SECRET_TOKEN:-}

View File

@@ -1,97 +0,0 @@
# Testing Docker Compose configuration for testing.dk0.dev
# Runs alongside production with isolated DB/Redis and different ports.
services:
portfolio-testing:
image: portfolio-app:testing
container_name: portfolio-app-testing
restart: unless-stopped
ports:
- "3002:3000" # Nginx Proxy Manager -> http://HOST:3002
environment:
- NODE_ENV=production
- DATABASE_URL=postgresql://portfolio_user:portfolio_testing_pass@postgres-testing:5432/portfolio_testing_db?schema=public
- REDIS_URL=redis://redis-testing:6379
- NEXT_PUBLIC_BASE_URL=${NEXT_PUBLIC_BASE_URL:-https://testing.dk0.dev}
- MY_EMAIL=${MY_EMAIL:-contact@dk0.dev}
- MY_INFO_EMAIL=${MY_INFO_EMAIL:-info@dk0.dev}
- MY_PASSWORD=${MY_PASSWORD}
- MY_INFO_PASSWORD=${MY_INFO_PASSWORD}
- ADMIN_BASIC_AUTH=${ADMIN_BASIC_AUTH:-admin:testing_password}
- ADMIN_SESSION_SECRET=${ADMIN_SESSION_SECRET}
- PRISMA_AUTO_BASELINE=${PRISMA_AUTO_BASELINE:-false}
- LOG_LEVEL=info
- N8N_WEBHOOK_URL=${N8N_WEBHOOK_URL:-}
- N8N_SECRET_TOKEN=${N8N_SECRET_TOKEN:-}
- N8N_API_KEY=${N8N_API_KEY:-}
volumes:
- portfolio_testing_data:/app/.next/cache
networks:
- portfolio_testing_net
- proxy
depends_on:
postgres-testing:
condition: service_healthy
redis-testing:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/api/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
postgres-testing:
image: postgres:16-alpine
container_name: portfolio-postgres-testing
restart: unless-stopped
environment:
- POSTGRES_DB=portfolio_testing_db
- POSTGRES_USER=portfolio_user
- POSTGRES_PASSWORD=portfolio_testing_pass
volumes:
- postgres_testing_data:/var/lib/postgresql/data
- ./scripts/init-db.sql:/docker-entrypoint-initdb.d/init-db.sql:ro
networks:
- portfolio_testing_net
ports:
- "5435:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U portfolio_user -d portfolio_testing_db"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
redis-testing:
image: redis:7-alpine
container_name: portfolio-redis-testing
restart: unless-stopped
command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
volumes:
- redis_testing_data:/data
networks:
- portfolio_testing_net
ports:
- "6382:6379"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
volumes:
portfolio_testing_data:
driver: local
postgres_testing_data:
driver: local
redis_testing_data:
driver: local
networks:
portfolio_testing_net:
driver: bridge
proxy:
external: true

View File

@@ -1,20 +0,0 @@
# CMS Guide (ohne extra Software)
Du brauchst **kein externes CMS**: das Projekt hat ein eingebautes, self-hosted CMS (Postgres + Admin UI).
## Wo ist das CMS?
- Öffne: `/manage`
- Login (Admin)
- Tab: **Content**
## Wie bearbeite ich Texte?
Im Content Tab kannst du auswählen:
- **Page key** (z.B. `home-hero`, `home-about`, `home-contact`, `privacy-policy`, `legal-notice`)
- **Locale** (`en` oder `de`)
Dann:
- Text bearbeiten (Rich Text)
- **Save**

View File

@@ -1,459 +0,0 @@
# 📚 Hardcover Integration Guide
## Übersicht
Diese Anleitung zeigt dir, wie du die Hardcover API in n8n integrierst, um deine aktuell gelesenen Bücher auf deiner Portfolio-Website anzuzeigen.
---
## 🎯 Was wird angezeigt?
Die Integration zeigt:
- **Titel** des aktuell gelesenen Buches
- **Bild** des Buchcovers
- **Autor(en)** des Buches
- **Lesefortschritt** (Prozent)
---
## 📋 Voraussetzungen
1. **Hardcover Account** mit API-Zugriff
2. **n8n Installation** (lokal oder Cloud)
3. **GraphQL Endpoint** von Hardcover
4. **API Credentials** (Token/Key) für Hardcover
---
## 🔧 n8n Workflow Setup
### Schritt 1: Webhook Node erstellen
1. Öffne n8n und erstelle einen neuen Workflow
2. Füge einen **Webhook** Node hinzu
3. Konfiguriere den Webhook:
- **HTTP Method**: `GET`
- **Path**: `/webhook/hardcover/currently-reading`
- **Response Mode**: `Last Node` (wenn du einen separaten Respond Node verwendest) oder `Respond to Webhook` (wenn der Webhook automatisch antworten soll)
- **Response Code**: `200`
**Wichtig:** Wenn du `Response Mode: Last Node` verwendest, musst du einen separaten "Respond to Webhook" Node am Ende hinzufügen. Wenn du `Response Mode: Respond to Webhook` verwendest, entferne den separaten "Respond to Webhook" Node.
### Schritt 2: HTTP Request Node für Hardcover API
1. Füge einen **HTTP Request** Node nach dem Webhook hinzu
2. Konfiguriere den Node:
**Settings:**
- **Method**: `POST`
- **URL**: `https://api.hardcover.app/graphql` (oder deine Hardcover GraphQL URL)
- **Authentication**: `Header Auth` oder `Generic Credential Type`
- **Name**: `Authorization`
- **Value**: `Bearer YOUR_HARDCOVER_TOKEN`
**Headers:**
```
Content-Type: application/json
```
**Body (JSON):**
```json
{
"query": "query GetCurrentlyReading { me { user_books(where: {status_id: {_eq: 2}}) { user_book_reads(limit: 1, order_by: {started_at: desc}) { progress } edition { title image { url } book { contributions { author { name } } } } } } }"
}
```
### Schritt 3: Daten transformieren
1. Füge einen **Code** Node oder **Set** Node hinzu
2. Transformiere die Hardcover-Antwort in das erwartete Format:
**Beispiel Transformation (Code Node - JavaScript):**
```javascript
// Hardcover API Response kommt als GraphQL Response
// Die Response ist ein Array: [{ data: { me: [{ user_books: [...] }] } }]
const graphqlResponse = $input.all()[0].json;
// Extrahiere die Daten - Response-Struktur: [{ data: { me: [{ user_books: [...] }] } }]
const responseData = Array.isArray(graphqlResponse) ? graphqlResponse[0] : graphqlResponse;
const meData = responseData?.data?.me;
const userBooks = (Array.isArray(meData) && meData[0]?.user_books) || meData?.user_books || [];
if (!userBooks || userBooks.length === 0) {
return {
json: {
currentlyReading: null
}
};
}
// Sortiere nach Fortschritt, falls mehrere Bücher vorhanden sind
const sortedBooks = userBooks.sort((a, b) => {
const progressA = a.user_book_reads?.[0]?.progress || 0;
const progressB = b.user_book_reads?.[0]?.progress || 0;
return progressB - progressA; // Höchster zuerst
});
// Formatiere alle Bücher
const formattedBooks = sortedBooks.map(book => {
const edition = book.edition || {};
const bookData = edition.book || {};
const contributions = bookData.contributions || [];
const authors = contributions
.filter(c => c.author && c.author.name)
.map(c => c.author.name);
const readData = book.user_book_reads?.[0] || {};
const progress = readData.progress || 0;
const image = edition.image?.url || null;
return {
title: edition.title || 'Unknown Title',
authors: authors.length > 0 ? authors : ['Unknown Author'],
image: image,
progress: Math.round(progress) || 0, // Progress ist bereits in Prozent (z.B. 65.75)
startedAt: readData.started_at || null,
};
});
// Gib alle Bücher zurück
return {
json: {
currentlyReading: formattedBooks.length > 0 ? formattedBooks : null
}
};
```
```
### Schritt 4: Response Node
**Option A: Automatische Response (Empfohlen)**
1. Setze den Webhook Node auf **Response Mode**: `Respond to Webhook`
2. **Entferne** den separaten "Respond to Webhook" Node
3. Der Webhook antwortet automatisch mit der Ausgabe des Code Nodes
**Option B: Manueller Respond Node**
1. Setze den Webhook Node auf **Response Mode**: `Last Node`
2. Füge einen **Respond to Webhook** Node nach dem Code Node hinzu
3. Verbinde den Code Node mit dem Respond to Webhook Node
4. Stelle sicher, dass die Antwort als JSON zurückgegeben wird
**Response Format (mit allen Büchern):**
```json
{
"currentlyReading": [
{
"title": "Ready Player Two",
"authors": ["Ernest Cline"],
"image": "https://assets.hardcover.app/...",
"progress": 66,
"startedAt": null
},
{
"title": "Die Mitternachtsbibliothek",
"authors": ["Matt Haig"],
"image": "https://assets.hardcover.app/...",
"progress": 57,
"startedAt": null
}
]
}
```
**Oder wenn kein Buch gelesen wird:**
```json
{
"currentlyReading": null
}
```
---
## 🔐 Environment Variables
Stelle sicher, dass folgende Umgebungsvariablen in deiner `.env` Datei gesetzt sind:
```bash
# n8n Configuration
N8N_WEBHOOK_URL=https://n8n.dk0.dev
N8N_SECRET_TOKEN=your-n8n-secret-token
N8N_API_KEY=your-n8n-api-key
# Hardcover API (optional, falls du es direkt verwenden willst)
HARDCOVER_API_URL=https://api.hardcover.app/graphql
HARDCOVER_API_TOKEN=your-hardcover-token
```
---
## 📡 API Endpoint
Die Portfolio-Website stellt folgenden Endpoint bereit:
**GET** `/api/n8n/hardcover/currently-reading`
### Response Format
**Erfolgreich:**
```json
{
"currentlyReading": {
"title": "Der Herr der Ringe",
"authors": ["J.R.R. Tolkien"],
"image": "https://example.com/book-cover.jpg",
"progress": 45,
"startedAt": "2024-01-15T10:00:00Z"
}
}
```
**Kein Buch:**
```json
{
"currentlyReading": null
}
```
**Fehler:**
```json
{
"error": "Rate limit exceeded. Please try again later."
}
```
### Rate Limiting
- **Development**: 60 Requests pro Minute
- **Production**: 10 Requests pro Minute
- **Cache**: 5 Minuten (300 Sekunden)
---
## 🎨 Frontend Integration
Die API sollte **nur einmal beim initialen Laden der Seite** aufgerufen werden.
**Beispiel React Component:**
```typescript
"use client";
import { useEffect, useState } from "react";
interface CurrentlyReading {
title: string;
authors: string[];
image: string | null;
progress: number;
startedAt: string | null;
}
export default function CurrentlyReadingWidget() {
const [book, setBook] = useState<CurrentlyReading | null>(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
// Nur einmal beim Laden der Seite
const fetchCurrentlyReading = async () => {
try {
const res = await fetch("/api/n8n/hardcover/currently-reading", {
cache: "default",
});
if (!res.ok) {
throw new Error("Failed to fetch");
}
const data = await res.json();
setBook(data.currentlyReading);
} catch (error) {
console.error("Error fetching currently reading:", error);
setBook(null);
} finally {
setLoading(false);
}
};
fetchCurrentlyReading();
}, []); // Leeres Array = nur einmal beim Mount
if (loading) {
return <div>Loading...</div>;
}
if (!book) {
return null; // Kein Buch = nichts anzeigen
}
return (
<div className="currently-reading-widget">
<img src={book.image || "/placeholder-book.png"} alt={book.title} />
<div>
<h3>{book.title}</h3>
<p>{book.authors.join(", ")}</p>
<div className="progress-bar">
<div style={{ width: `${book.progress}%` }} />
</div>
<p>{book.progress}% gelesen</p>
</div>
</div>
);
}
```
---
## 🔍 Troubleshooting
### Problem: "Unused Respond to Webhook node found in the workflow"
**Fehler:**
```
n8n hardcover webhook failed: 500 {"code":0,"message":"Unused Respond to Webhook node found in the workflow"}
```
**Lösung:**
Dieser Fehler tritt auf, wenn du einen separaten "Respond to Webhook" Node hast, der nicht korrekt mit dem Workflow verbunden ist.
**Option 1: Automatische Response verwenden (Empfohlen)**
1. Öffne den **Webhook** Node
2. Stelle sicher, dass **Response Mode** auf `Respond to Webhook` gesetzt ist
3. Entferne den separaten "Respond to Webhook" Node (falls vorhanden)
4. Der Webhook Node antwortet automatisch mit der letzten Node-Ausgabe
**Option 2: Manueller Respond Node**
1. Falls du einen separaten "Respond to Webhook" Node verwenden möchtest:
- Stelle sicher, dass dieser Node **direkt nach dem Code/Set Node** verbunden ist
- Der Webhook Node sollte auf **Response Mode: `Last Node`** gesetzt sein
- Der "Respond to Webhook" Node muss die Daten vom Code Node erhalten
**Workflow-Struktur (Option 1 - Empfohlen):**
```
Webhook (Response Mode: Respond to Webhook)
HTTP Request (Hardcover API)
Code Node (Transformation)
(Webhook antwortet automatisch mit Code Node Output)
```
**Workflow-Struktur (Option 2):**
```
Webhook (Response Mode: Last Node)
HTTP Request (Hardcover API)
Code Node (Transformation)
Respond to Webhook Node
```
### Problem: n8n Webhook gibt leere Antwort zurück
**Lösung:**
- Prüfe, ob der Hardcover API Token korrekt ist
- Stelle sicher, dass der GraphQL Query korrekt formatiert ist
- Prüfe die n8n Logs für Fehlerdetails
- Stelle sicher, dass der Code Node die Daten korrekt zurückgibt (`return { json: {...} }`)
### Problem: API gibt `null` zurück, obwohl ein Buch gelesen wird
**Lösung:**
- Prüfe, ob `status_id: 2` der korrekte Status für "Currently Reading" ist
- Stelle sicher, dass der GraphQL Query die richtigen Felder abfragt
- Prüfe die Hardcover API direkt mit einem GraphQL Client
- Debug: Füge einen `console.log` im Code Node hinzu, um die rohe Response zu sehen
### Problem: Rate Limit Fehler
**Lösung:**
- Die API cached Daten für 5 Minuten
- Reduziere die Anzahl der API-Aufrufe im Frontend
- Stelle sicher, dass die API nur einmal beim Laden der Seite aufgerufen wird
### Problem: CORS Fehler
**Lösung:**
- n8n sollte die CORS-Header korrekt setzen
- Prüfe die n8n Webhook-Konfiguration
- Stelle sicher, dass die Portfolio-Website-URL in n8n erlaubt ist
---
## 📚 GraphQL Query Details
Der verwendete GraphQL Query:
```graphql
query GetCurrentlyReading {
me {
user_books(where: {status_id: {_eq: 2}}) {
user_book_reads(limit: 1, order_by: {started_at: desc}) {
progress
}
edition {
title
image {
url
}
book {
contributions {
author {
name
}
}
}
}
}
}
}
```
**Erklärung:**
- `status_id: {_eq: 2}` = Filtert nach Büchern mit Status "Currently Reading" (ID 2)
- `user_book_reads(limit: 1, order_by: {started_at: desc})` = Holt den neuesten Lesefortschritt
- `progress` = Lesefortschritt als Dezimalzahl (0.0 - 1.0)
- `edition.title` = Titel des Buches
- `edition.image.url` = URL zum Buchcover
- `book.contributions[].author.name` = Liste der Autorennamen
---
## 🚀 Deployment
1. **n8n Workflow aktivieren**
- Stelle sicher, dass der Workflow aktiviert ist
- Teste den Webhook mit einem GET Request
2. **Environment Variables setzen**
- Füge `N8N_WEBHOOK_URL` zur `.env` hinzu
- Füge `N8N_SECRET_TOKEN` hinzu (optional, für Auth)
3. **Frontend Integration**
- Füge die `CurrentlyReadingWidget` Komponente zur Homepage hinzu
- Stelle sicher, dass die API nur einmal aufgerufen wird
4. **Testen**
- Lade die Homepage neu
- Prüfe die Browser-Konsole für Fehler
- Prüfe die Network-Tab für API-Aufrufe
---
## 📝 Notizen
- Die API cached Daten für **5 Minuten**, um n8n nicht zu überlasten
- Die API sollte **nur einmal beim initialen Laden** der Seite aufgerufen werden
- Falls kein Buch gelesen wird, gibt die API `null` zurück
- Die API verwendet Rate Limiting, um Missbrauch zu verhindern
---
## 🔗 Weitere Ressourcen
- [Hardcover API Dokumentation](https://hardcover.app)
- [n8n Dokumentation](https://docs.n8n.io)
- [GraphQL Best Practices](https://graphql.org/learn/best-practices/)

View File

@@ -1,97 +0,0 @@
# Operations Guide (Dev, Texts, Testing, Deployment)
## Where do I update texts?
### 1) UI texts (recommended default)
- **English**: `messages/en.json`
- **Deutsch**: `messages/de.json`
These are loaded via `next-intl` and are the source of truth for **labels, headings, buttons, validation messages** etc.
### 2) Page content via CMS (optional overrides)
Some sections support a CMS override via `/api/content/page` (falls back to `messages/*` automatically):
- `home-hero`
- `home-about`
- `home-contact`
If your DB/CMS tables are not available, the site will **not crash** and will keep showing the `messages/*` content.
## Local development
### Requirements
- Node.js 18+
- Docker (optional but recommended for DB/Redis)
### Install
```bash
npm ci
```
### Run (recommended)
```bash
npm run dev
```
### Run without Docker (no DB/Redis)
```bash
npm run dev:simple
```
### Run plain Next.js dev server
```bash
npm run dev:next
```
### Environment
Copy `env.example``.env.local` and adjust.
## Testing
### Unit tests (Jest)
```bash
npm run test
```
### E2E tests (Playwright)
```bash
npm run test:e2e
```
### Useful subsets
```bash
npm run test:hydration
npm run test:critical
```
## Deployment overview
### Branches
- `dev` → staging/dev environment
- `production` → live environment
Deployments are driven by CI workflows in `.gitea/workflows/`.
### Health checks
- `/api/health`
## Nginx Proxy Manager (high level)
Create proxy hosts for your domains pointing to the respective ports.
If you see `421 Misdirected Request`, make sure the reverse proxy forwards `Host` properly and consider forcing `proxy_http_version 1.1`.
## Gitea variables/secrets (high level)
Minimum required secrets/variables depend on which features you enable, but typical production/staging need:
- Base URLs (per environment)
- Admin auth/session secrets
- Email credentials
- Optional n8n webhook secret/token
## Troubleshooting
### “docker compose not found”
Use `npm run dev:simple` or install Docker.
### Prisma migrations / existing DB
If you introduce migrations into an existing DB, baseline/resolve the initial migration once to avoid “table already exists” issues.

View File

@@ -1,32 +0,0 @@
import { test, expect } from "@playwright/test";
test.describe("ActivityFeed reload rendering", () => {
test("feed stays visible and dark after reload", async ({ page }) => {
await page.goto("/en", { waitUntil: "domcontentloaded" });
const feed = page.locator('[class*="bg-black/95"]').filter({ hasText: "Live Activity" }).first();
await expect(feed).toBeVisible({ timeout: 15000 });
const initialBox = await feed.boundingBox();
expect(initialBox).not.toBeNull();
expect(initialBox!.width).toBeGreaterThan(200);
expect(initialBox!.height).toBeGreaterThan(30);
const initialOpacity = await feed.evaluate((el) => getComputedStyle(el).opacity);
expect(Number(initialOpacity)).toBeGreaterThan(0.5);
await page.reload({ waitUntil: "domcontentloaded" });
const feedAfter = page.locator('[class*="bg-black/95"]').filter({ hasText: "Live Activity" }).first();
await expect(feedAfter).toBeVisible({ timeout: 15000 });
const afterBox = await feedAfter.boundingBox();
expect(afterBox).not.toBeNull();
expect(afterBox!.width).toBeGreaterThan(200);
expect(afterBox!.height).toBeGreaterThan(30);
const afterOpacity = await feedAfter.evaluate((el) => getComputedStyle(el).opacity);
expect(Number(afterOpacity)).toBeGreaterThan(0.5);
});
});

View File

@@ -1,27 +0,0 @@
import { test, expect } from "@playwright/test";
test.describe("Consent banner", () => {
test("banner shows and can be accepted", async ({ page, context }) => {
// Start clean
await context.clearCookies();
await page.goto("/en", { waitUntil: "domcontentloaded" });
// Banner should appear on public pages when no consent is set yet
const bannerTitle = page.getByText(/Privacy settings|Datenschutz-Einstellungen/i);
await expect(bannerTitle).toBeVisible({ timeout: 10000 });
// Accept all
const acceptAll = page.getByRole("button", { name: /Accept all|Alles akzeptieren/i });
await acceptAll.click();
// Banner disappears
await expect(bannerTitle).toBeHidden({ timeout: 10000 });
// Cookie is written
const cookies = await context.cookies();
const consentCookie = cookies.find((c) => c.name === "dk0_consent_v1");
expect(consentCookie).toBeTruthy();
});
});

View File

@@ -6,7 +6,7 @@ import { test, expect } from '@playwright/test';
*/ */
test.describe('Critical Paths', () => { test.describe('Critical Paths', () => {
test('Home page loads and displays correctly', async ({ page }) => { test('Home page loads and displays correctly', async ({ page }) => {
await page.goto('/en', { waitUntil: 'networkidle' }); await page.goto('/', { waitUntil: 'networkidle' });
// Wait for page to be fully loaded // Wait for page to be fully loaded
await page.waitForLoadState('domcontentloaded'); await page.waitForLoadState('domcontentloaded');
@@ -25,7 +25,7 @@ test.describe('Critical Paths', () => {
}); });
test('Projects page loads and displays projects', async ({ page }) => { test('Projects page loads and displays projects', async ({ page }) => {
await page.goto('/en/projects', { waitUntil: 'networkidle' }); await page.goto('/projects', { waitUntil: 'networkidle' });
// Wait for projects to load // Wait for projects to load
await page.waitForLoadState('domcontentloaded'); await page.waitForLoadState('domcontentloaded');
@@ -45,7 +45,7 @@ test.describe('Critical Paths', () => {
test('Individual project page loads', async ({ page }) => { test('Individual project page loads', async ({ page }) => {
// First, get a project slug from the projects page // First, get a project slug from the projects page
await page.goto('/en/projects', { waitUntil: 'networkidle' }); await page.goto('/projects', { waitUntil: 'networkidle' });
await page.waitForLoadState('domcontentloaded'); await page.waitForLoadState('domcontentloaded');
// Try to find a project link // Try to find a project link

View File

@@ -19,11 +19,9 @@ test.describe('Hydration Tests', () => {
} }
}); });
// Navigate to home page. // Navigate to home page
// Avoid `networkidle` because the app has background polling/analytics requests. await page.goto('/', { waitUntil: 'networkidle' });
await page.goto('/en', { waitUntil: 'domcontentloaded' }); await page.waitForLoadState('domcontentloaded');
// Give hydration a moment to run
await page.waitForTimeout(1000);
// Check for hydration errors // Check for hydration errors
const hydrationErrors = consoleErrors.filter(error => const hydrationErrors = consoleErrors.filter(error =>
@@ -53,8 +51,8 @@ test.describe('Hydration Tests', () => {
} }
}); });
await page.goto('/en', { waitUntil: 'domcontentloaded' }); await page.goto('/');
await page.waitForTimeout(500); await page.waitForLoadState('networkidle');
// Check for duplicate key warnings // Check for duplicate key warnings
const keyWarnings = consoleWarnings.filter(warning => const keyWarnings = consoleWarnings.filter(warning =>
@@ -73,15 +71,14 @@ test.describe('Hydration Tests', () => {
} }
}); });
await page.goto('/en', { waitUntil: 'domcontentloaded' }); await page.goto('/', { waitUntil: 'networkidle' });
await page.waitForTimeout(500); await page.waitForLoadState('domcontentloaded');
// Navigate to projects page via link // Navigate to projects page via link
const projectsLink = page.locator('a[href*="/projects"]').first(); const projectsLink = page.locator('a[href="/projects"], a[href*="projects"]').first();
if (await projectsLink.count() > 0) { if (await projectsLink.count() > 0) {
await projectsLink.click(); await projectsLink.click();
await page.waitForLoadState('domcontentloaded'); await page.waitForLoadState('domcontentloaded');
await page.waitForTimeout(500);
// Check for errors after navigation // Check for errors after navigation
const hydrationErrors = consoleErrors.filter(error => const hydrationErrors = consoleErrors.filter(error =>
@@ -93,13 +90,13 @@ test.describe('Hydration Tests', () => {
}); });
test('Server and client HTML match', async ({ page }) => { test('Server and client HTML match', async ({ page }) => {
await page.goto('/en'); await page.goto('/');
// Get initial HTML // Get initial HTML
const initialHTML = await page.content(); const initialHTML = await page.content();
// Wait for React to hydrate (avoid networkidle due to background requests) // Wait for React to hydrate
await page.waitForTimeout(1000); await page.waitForLoadState('networkidle');
// Get HTML after hydration // Get HTML after hydration
const hydratedHTML = await page.content(); const hydratedHTML = await page.content();
@@ -111,28 +108,21 @@ test.describe('Hydration Tests', () => {
}); });
test('Interactive elements work after hydration', async ({ page }) => { test('Interactive elements work after hydration', async ({ page }) => {
await page.goto('/en'); await page.goto('/');
await page.waitForTimeout(1000); await page.waitForLoadState('networkidle');
// Try to find and click interactive elements // Try to find and click interactive elements
const buttons = page.locator('button, a[role="button"]'); const buttons = page.locator('button, a[role="button"]');
const buttonCount = await buttons.count(); const buttonCount = await buttons.count();
if (buttonCount > 0) { if (buttonCount > 0) {
// Find a visible interactive element (desktop hides some mobile-only buttons) const firstButton = buttons.first();
let clicked = false; await expect(firstButton).toBeVisible();
for (let i = 0; i < Math.min(buttonCount, 25); i++) {
const candidate = buttons.nth(i); // Try clicking (should not throw)
// eslint-disable-next-line no-await-in-loop await firstButton.click().catch(() => {
if (await candidate.isVisible()) { // Some buttons might be disabled, that's OK
await candidate.click().catch(() => { });
// Some buttons might be disabled or covered, that's OK
});
clicked = true;
break;
}
}
expect(clicked).toBe(true);
} }
}); });
}); });

View File

@@ -1,25 +0,0 @@
import { test, expect } from "@playwright/test";
test.describe("i18n routing", () => {
test("language switcher navigates between locales", async ({ page }) => {
await page.goto("/en", { waitUntil: "domcontentloaded" });
// Locale switchers are links (work even without hydration)
const deLink = page.getByRole("link", { name: "Sprache auf Deutsch umstellen" });
if (await deLink.count()) {
// Verify an EN label is present before switching (nav.home)
await expect(page.getByRole("link", { name: "Home" })).toBeVisible();
await Promise.all([
page.waitForURL(/\/de(\/|$)/, { timeout: 30000 }),
deLink.click(),
]);
// Verify the nav label updates after switching
await expect(page.getByRole("link", { name: "Start" })).toBeVisible();
} else {
test.skip();
}
});
});

View File

@@ -1,22 +0,0 @@
import { test, expect } from "@playwright/test";
test.describe("SEO endpoints", () => {
test("robots.txt is served and contains sitemap", async ({ request }) => {
const res = await request.get("/robots.txt");
expect(res.ok()).toBeTruthy();
const txt = await res.text();
expect(txt).toContain("User-agent:");
expect(txt).toContain("Sitemap:");
});
test("sitemap.xml is served and contains locale routes", async ({ request }) => {
const res = await request.get("/sitemap.xml");
expect(res.ok()).toBeTruthy();
const xml = await res.text();
expect(xml).toContain('<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">');
// At least the localized home routes should exist
expect(xml).toMatch(/\/en<\/loc>/);
expect(xml).toMatch(/\/de<\/loc>/);
});
});

View File

@@ -34,14 +34,6 @@ N8N_API_KEY=your-n8n-api-key
# JWT_SECRET=your-jwt-secret # JWT_SECRET=your-jwt-secret
# ENCRYPTION_KEY=your-encryption-key # ENCRYPTION_KEY=your-encryption-key
ADMIN_BASIC_AUTH=admin:your_secure_password_here ADMIN_BASIC_AUTH=admin:your_secure_password_here
ADMIN_SESSION_SECRET=change_me_to_a_long_random_string_at_least_32_chars
# Prisma migrations at container startup
# - default: migrations are executed (`prisma migrate deploy`)
# - set to true ONCE if you already have an existing DB that was created before migrations existed
PRISMA_AUTO_BASELINE=false
# emergency switch (not recommended for normal operation)
# SKIP_PRISMA_MIGRATE=true
# Monitoring (optional) # Monitoring (optional)
# SENTRY_DSN=your-sentry-dsn # SENTRY_DSN=your-sentry-dsn

View File

@@ -1,3 +0,0 @@
export const locales = ["en", "de"] as const;
export type AppLocale = (typeof locales)[number];

View File

@@ -1,15 +0,0 @@
import { getRequestConfig } from "next-intl/server";
import { locales } from "./locales";
export { locales, type AppLocale } from "./locales";
export default getRequestConfig(async ({ locale }) => {
// next-intl can call us with unknown/undefined locales; fall back safely
const requested = typeof locale === "string" ? locale : "en";
const safeLocale = (locales as readonly string[]).includes(requested) ? requested : "en";
return {
locale: safeLocale,
messages: (await import(`../messages/${safeLocale}.json`)).default,
};
});

View File

@@ -26,69 +26,6 @@ jest.mock("next/navigation", () => ({
notFound: jest.fn(), notFound: jest.fn(),
})); }));
// Mock next-intl (ESM) for Jest
jest.mock("next-intl", () => ({
useLocale: () => "en",
useTranslations:
(namespace?: string) =>
(key: string) => {
if (namespace === "nav") {
const map: Record<string, string> = {
home: "Home",
about: "About",
projects: "Projects",
contact: "Contact",
};
return map[key] || key;
}
if (namespace === "common") {
const map: Record<string, string> = {
backToHome: "Back to Home",
backToProjects: "Back to Projects",
};
return map[key] || key;
}
if (namespace === "home.hero") {
const map: Record<string, string> = {
"features.f1": "Next.js & Flutter",
"features.f2": "Docker Swarm & CI/CD",
"features.f3": "Self-Hosted Infrastructure",
description:
"Student and passionate self-hoster building full-stack web apps and mobile solutions. I run my own infrastructure and love exploring DevOps.",
ctaWork: "View My Work",
ctaContact: "Contact Me",
};
return map[key] || key;
}
if (namespace === "home.about") {
const map: Record<string, string> = {
title: "About Me",
p1: "Hi, I'm Dennis a student and passionate self-hoster based in Osnabrück, Germany.",
p2: "I love building full-stack web applications with Next.js and mobile apps with Flutter. But what really excites me is DevOps: I run my own infrastructure and automate deployments with CI/CD.",
p3: "When I'm not coding or tinkering with servers, you'll find me gaming, jogging, or experimenting with automation workflows.",
funFactTitle: "Fun Fact",
funFactBody:
"Even though I automate a lot, I still use pen and paper for my calendar and notes it helps me stay focused.",
};
return map[key] || key;
}
if (namespace === "home.contact") {
const map: Record<string, string> = {
title: "Contact Me",
subtitle:
"Interested in working together or have questions about my projects? Feel free to reach out!",
getInTouch: "Get In Touch",
getInTouchBody:
"I'm always available to discuss new opportunities, interesting projects, or simply chat about technology and innovation.",
};
return map[key] || key;
}
return key;
},
NextIntlClientProvider: ({ children }: { children: React.ReactNode }) =>
React.createElement(React.Fragment, null, children),
}));
// Mock next/link // Mock next/link
jest.mock("next/link", () => { jest.mock("next/link", () => {
return function Link({ return function Link({

View File

@@ -25,21 +25,12 @@ export interface WebVitalsMetric {
// Track custom events to Umami // Track custom events to Umami
export const trackEvent = (event: string, data?: Record<string, unknown>) => { export const trackEvent = (event: string, data?: Record<string, unknown>) => {
if (typeof window === "undefined") return; if (typeof window !== 'undefined' && window.umami) {
const trackFn = window.umami?.track; window.umami.track(event, {
if (typeof trackFn !== "function") return;
try {
trackFn(event, {
...data, ...data,
timestamp: Date.now(), timestamp: Date.now(),
url: window.location.pathname, url: window.location.pathname,
}); });
} catch (error) {
// Silently fail - analytics must never break the app
if (process.env.NODE_ENV === "development") {
console.warn("Error tracking Umami event:", error);
}
} }
}; };

View File

@@ -1,117 +1,4 @@
import { NextRequest } from 'next/server'; import { NextRequest } from 'next/server';
import crypto from 'crypto';
const DEFAULT_INSECURE_ADMIN = 'admin:default_password_change_me';
const SESSION_DURATION_MS = 2 * 60 * 60 * 1000; // 2 hours
function base64UrlEncode(input: string | Buffer): string {
const buf = typeof input === 'string' ? Buffer.from(input, 'utf8') : input;
return buf.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/g, '');
}
function base64UrlDecodeToString(input: string): string {
const normalized = input.replace(/-/g, '+').replace(/_/g, '/');
const pad = normalized.length % 4 === 0 ? '' : '='.repeat(4 - (normalized.length % 4));
return Buffer.from(normalized + pad, 'base64').toString('utf8');
}
function base64UrlDecodeToBuffer(input: string): Buffer {
const normalized = input.replace(/-/g, '+').replace(/_/g, '/');
const pad = normalized.length % 4 === 0 ? '' : '='.repeat(4 - (normalized.length % 4));
return Buffer.from(normalized + pad, 'base64');
}
export function getClientIp(request: NextRequest): string {
const xff = request.headers.get('x-forwarded-for');
if (xff) {
// x-forwarded-for can be a list: client, proxy1, proxy2
return xff.split(',')[0]?.trim() || 'unknown';
}
return request.headers.get('x-real-ip') || 'unknown';
}
function getAdminCredentials(): { username: string; password: string } | null {
const raw = process.env.ADMIN_BASIC_AUTH;
if (!raw || raw.trim() === '' || raw === DEFAULT_INSECURE_ADMIN) return null;
const idx = raw.indexOf(':');
if (idx <= 0 || idx === raw.length - 1) return null;
return { username: raw.slice(0, idx), password: raw.slice(idx + 1) };
}
function getSessionSecret(): string | null {
const secret = process.env.ADMIN_SESSION_SECRET;
if (!secret || secret.trim().length < 32) return null; // require a reasonably strong secret
return secret;
}
type SessionPayload = {
v: 1;
iat: number;
rnd: string;
ip: string;
ua: string;
};
export function createSessionToken(request: NextRequest): string | null {
const secret = getSessionSecret();
if (!secret) return null;
const payload: SessionPayload = {
v: 1,
iat: Date.now(),
rnd: crypto.randomBytes(32).toString('hex'),
ip: getClientIp(request),
ua: request.headers.get('user-agent') || 'unknown',
};
const payloadB64 = base64UrlEncode(JSON.stringify(payload));
const sig = crypto.createHmac('sha256', secret).update(payloadB64).digest();
const sigB64 = base64UrlEncode(sig);
return `${payloadB64}.${sigB64}`;
}
export function verifySessionToken(request: NextRequest, token: string): boolean {
const secret = getSessionSecret();
if (!secret) return false;
const parts = token.split('.');
if (parts.length !== 2) return false;
const [payloadB64, sigB64] = parts;
if (!payloadB64 || !sigB64) return false;
let providedSigBytes: Buffer;
try {
providedSigBytes = base64UrlDecodeToBuffer(sigB64);
} catch {
return false;
}
const expectedSigBytes = crypto.createHmac('sha256', secret).update(payloadB64).digest();
if (providedSigBytes.length !== expectedSigBytes.length) return false;
if (!crypto.timingSafeEqual(providedSigBytes, expectedSigBytes)) return false;
let payload: SessionPayload;
try {
payload = JSON.parse(base64UrlDecodeToString(payloadB64)) as SessionPayload;
} catch {
return false;
}
if (!payload || payload.v !== 1 || typeof payload.iat !== 'number' || typeof payload.rnd !== 'string') {
return false;
}
const now = Date.now();
if (now - payload.iat > SESSION_DURATION_MS) return false;
// Bind token to client IP + UA (best-effort; "unknown" should not hard-fail)
const currentIp = getClientIp(request);
const currentUa = request.headers.get('user-agent') || 'unknown';
if (payload.ip !== 'unknown' && currentIp !== 'unknown' && payload.ip !== currentIp) return false;
if (payload.ua !== 'unknown' && currentUa !== 'unknown' && payload.ua !== currentUa) return false;
return true;
}
// Server-side authentication utilities // Server-side authentication utilities
export function verifyAdminAuth(request: NextRequest): boolean { export function verifyAdminAuth(request: NextRequest): boolean {
@@ -124,14 +11,14 @@ export function verifyAdminAuth(request: NextRequest): boolean {
try { try {
const base64Credentials = authHeader.split(' ')[1]; const base64Credentials = authHeader.split(' ')[1];
const credentials = Buffer.from(base64Credentials, 'base64').toString('utf8'); const credentials = atob(base64Credentials);
const [username, password] = credentials.split(':'); const [username, password] = credentials.split(':');
// Get admin credentials from environment // Get admin credentials from environment
const creds = getAdminCredentials(); const adminAuth = process.env.ADMIN_BASIC_AUTH || 'admin:default_password_change_me';
if (!creds) return false; const [expectedUsername, expectedPassword] = adminAuth.split(':');
return username === creds.username && password === creds.password; return username === expectedUsername && password === expectedPassword;
} catch { } catch {
return false; return false;
} }
@@ -159,7 +46,31 @@ export function verifySessionAuth(request: NextRequest): boolean {
if (!sessionToken) return false; if (!sessionToken) return false;
try { try {
return verifySessionToken(request, sessionToken); // Decode and validate session token
const decodedJson = atob(sessionToken);
const sessionData = JSON.parse(decodedJson);
// Validate session data structure
if (!sessionData.timestamp || !sessionData.random || !sessionData.ip || !sessionData.userAgent) {
return false;
}
// Check if session is still valid (2 hours)
const sessionTime = sessionData.timestamp;
const now = Date.now();
const sessionDuration = 2 * 60 * 60 * 1000; // 2 hours
if (now - sessionTime > sessionDuration) {
return false;
}
// Validate IP address (optional, but good security practice)
const currentIp = request.headers.get('x-forwarded-for') || request.headers.get('x-real-ip') || 'unknown';
if (sessionData.ip !== currentIp) {
return false;
}
return true;
} catch { } catch {
return false; return false;
} }

View File

@@ -10,9 +10,8 @@ export const apiCache = {
if (page !== '1') keyParts.push(`page:${page}`); if (page !== '1') keyParts.push(`page:${page}`);
if (limit !== '50') keyParts.push(`limit:${limit}`); if (limit !== '50') keyParts.push(`limit:${limit}`);
if (category) keyParts.push(`cat:${category}`); if (category) keyParts.push(`cat:${category}`);
// Avoid cache fragmentation like `feat:undefined` when params omit the field if (featured !== null) keyParts.push(`feat:${featured}`);
if (featured != null) keyParts.push(`feat:${featured}`); if (published !== null) keyParts.push(`pub:${published}`);
if (published != null) keyParts.push(`pub:${published}`);
if (difficulty) keyParts.push(`diff:${difficulty}`); if (difficulty) keyParts.push(`diff:${difficulty}`);
if (search) keyParts.push(`search:${search}`); if (search) keyParts.push(`search:${search}`);

Some files were not shown because too many files have changed in this diff Show More