Files
FullStackTemplate/.vscode/cleanup-ports.sh
Christian Schindler 4a6b4a0ae8 feat: Enhance security and validation in backend
- Added helmet for security headers and configured content security policy
- Implemented CORS with a whitelist for allowed origins
- Introduced express-validator for input validation in API endpoints
- Set request size limits to prevent DoS attacks
- Added global error handling and 404 response
- Updated TypeScript configuration to use node16 module resolution
- Improved Docker Compose configuration for security and resource limits
- Created a comprehensive .env.example for environment configuration
- Implemented automated security scans in CI/CD with Trivy
- Added cleanup script for debugging ports
- Established a detailed security policy document
2025-12-01 08:37:35 +01:00

60 lines
2.0 KiB
Bash

#!/bin/bash
# Debug Port Cleanup Script
# Stellt sicher, dass die Debug-Ports frei sind und beendet laufende Prozesse
set -euo pipefail
PORTS=("3000" "3001" "9229" "5173" "9222")
echo "🧹 Prüfe und bereinige Debug-Ports (${PORTS[*]})..."
have_lsof=false
have_fuser=false
have_ss=false
command -v lsof >/dev/null 2>&1 && have_lsof=true
command -v fuser >/dev/null 2>&1 && have_fuser=true
command -v ss >/dev/null 2>&1 && have_ss=true
if [ "$have_lsof" = false ] && [ "$have_fuser" = false ] && [ "$have_ss" = false ]; then
echo "⚠️ Weder lsof noch fuser/ss verfügbar. Ports können nicht geprüft/gekilled werden."
exit 0
fi
for PORT in "${PORTS[@]}"; do
PIDS=""
if [ "$have_lsof" = true ]; then
PIDS=$({ lsof -ti :"$PORT" 2>/dev/null || true; } | tr '\n' ' ')
elif [ "$have_fuser" = true ]; then
# fuser listet PIDs, -n tcp beschränkt auf TCP
PIDS=$({ fuser -n tcp "$PORT" 2>/dev/null || true; } | tr '\n' ' ')
elif [ "$have_ss" = true ]; then
# ss fallback, extrahiere pid=... aus der letzten Spalte
PIDS=$({ ss -ltnp "sport = :$PORT" 2>/dev/null || true; } | awk 'NR>1 {split($NF,pid,"pid="); split(pid[2],p,","); if(p[1]!=""){print p[1]}}' | tr '\n' ' ')
fi
if [ -n "$PIDS" ]; then
echo " ✓ Beende Prozesse auf Port $PORT (PID: $PIDS)"
if [ "$have_fuser" = true ]; then
fuser -k -n tcp "$PORT" 2>/dev/null || true
else
kill -9 $PIDS 2>/dev/null || true
fi
else
echo " ○ Port $PORT ist frei"
fi
done
echo "✅ Port-Bereinigung abgeschlossen."
echo ""
echo "Belegte Debug-Ports aktuell:"
if [ "$have_lsof" = true ]; then
lsof -i :3000 -i :3001 -i :9229 -i :5173 -i :9222 2>/dev/null || echo " Alle Debug-Ports sind frei ✓"
elif [ "$have_ss" = true ]; then
ss -ltnp "( sport = :3000 or sport = :3001 or sport = :9229 or sport = :5173 or sport = :9222 )" 2>/dev/null || echo " Alle Debug-Ports sind frei ✓"
else
echo " Port-Status nicht prüfbar (lsof/ss fehlen), Cleanup wurde dennoch ausgeführt."
fi