diff --git a/backend/compose.yaml b/backend/compose.yaml index b1b03cc..74f6a54 100644 --- a/backend/compose.yaml +++ b/backend/compose.yaml @@ -68,19 +68,6 @@ services: condition: service_started mongo: condition: service_healthy - nginx: - image: nginx:alpine - container_name: ctf-nginx - restart: unless-stopped - ports: - - "3000:80" - volumes: - - ./nginx.conf:/etc/nginx/nginx.conf:ro - networks: - - ctf-network - depends_on: - - app - networks: ctf-network: driver: bridge diff --git a/backend/nginx.conf b/backend/nginx.conf deleted file mode 100644 index 321e104..0000000 --- a/backend/nginx.conf +++ /dev/null @@ -1,32 +0,0 @@ -events { - # Configuration for connection processing - worker_connections 1024; -} -http { - include mime.types; - - upstream backendserver { - server ctf-backend:3000; - } - - server { - listen 80; # Listen on standard web port - server_name _; - - location / { - # Allow Cors Headers for Frontend - add_header 'Access-Control-Allow-Origin' 'http://localhost:5173' always; - # Allow specific methods - add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE' always; - - # 3. Allow specific headers (like Content-Type or Authorization) - add_header 'Access-Control-Allow-Headers' 'X-Requested-With,Content-Type,Authorization' always; - proxy_pass http://backendserver/; - # Important headers to keep the user's info intact - 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; - } - } -} diff --git a/backend/src/utils/dockerUtils.ts b/backend/src/utils/dockerUtils.ts index 16c8775..76340e8 100644 --- a/backend/src/utils/dockerUtils.ts +++ b/backend/src/utils/dockerUtils.ts @@ -14,16 +14,19 @@ import path from 'node:path'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); +const dockerConfig: Dockerode.DockerOptions = + configEnv.nodeEnv === 'production' + ? { + host: 'EC2:IP_Address', //fron env it should not be hardcoded + protocol: 'https', + port: 2376, + ca: fs.readFileSync(path.join(__dirname, 'ca.pem')), + cert: fs.readFileSync(path.join(__dirname, 'cert.pem')), + key: fs.readFileSync(path.join(__dirname, 'key.pem')), + } + : {}; -// for ec2 connection -const docker = new Dockerode({ - host: 'EC2:IP_Address', //fron env it should not be hardcoded - protocol: 'https', - port: 2376, - ca: fs.readFileSync(path.join(__dirname, 'ca.pem')), - cert: fs.readFileSync(path.join(__dirname, 'cert.pem')), - key: fs.readFileSync(path.join(__dirname, 'key.pem')), -}); +const docker = new Dockerode(dockerConfig); /** * Generates a random port number in the range [3001, 4000) that is not in use or reserved. * diff --git a/frontend/nginx.conf b/frontend/nginx.conf index 8222b8f..6a8b01d 100644 --- a/frontend/nginx.conf +++ b/frontend/nginx.conf @@ -1,3 +1,7 @@ +upstream backendserver { + server ctf-backend:3000; +} + server { listen 0.0.0.0:80; server_name _; @@ -44,7 +48,7 @@ server { } # API proxy to backend location /api/ { - proxy_pass http://127.0.0.1:3000/api/; + proxy_pass http://backendserver; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; diff --git a/frontend/src/components/auth/Login.tsx b/frontend/src/components/auth/Login.tsx index a27a119..110d621 100644 --- a/frontend/src/components/auth/Login.tsx +++ b/frontend/src/components/auth/Login.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import { useAuth } from '../../hooks/useAuth'; import { useNavigate, Link } from 'react-router-dom'; import { getErrorMessage } from '../../utils/errorHandler'; @@ -16,7 +16,11 @@ const Login: React.FC = () => { const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); - if (isAuthenticated) navigate(ROUTES.CHALLENGES); + useEffect(() => { + if (isAuthenticated) { + navigate(ROUTES.CHALLENGES); + } + }, [isAuthenticated, navigate]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); diff --git a/frontend/src/components/challenges/ChallengeDetail.tsx b/frontend/src/components/challenges/ChallengeDetail.tsx index ce741f1..ec8e17e 100644 --- a/frontend/src/components/challenges/ChallengeDetail.tsx +++ b/frontend/src/components/challenges/ChallengeDetail.tsx @@ -85,7 +85,8 @@ const ChallengeDetail: React.FC = () => { setMessage({ type: 'error', text: 'Incorrect flag. Try again!' }); } } catch (error: unknown) { - getErrorMessage(error); + const errorMessage = getErrorMessage(error); + setMessage({ type: 'error', text: errorMessage }); } finally { setLoading(false); } diff --git a/frontend/src/components/common/ProtectedRoute.tsx b/frontend/src/components/common/ProtectedRoute.tsx index 56453a9..06ce1d9 100644 --- a/frontend/src/components/common/ProtectedRoute.tsx +++ b/frontend/src/components/common/ProtectedRoute.tsx @@ -1,11 +1,16 @@ import React from 'react'; import { useAuth } from '../../hooks/useAuth'; import { Navigate } from 'react-router-dom'; +import { ROUTES } from '../../utils/constants'; const ProtectedRoute: React.FC<{ children: React.ReactNode }> = ({ children, }) => { const { isAuthenticated } = useAuth(); - return isAuthenticated ? <>{children} : ; + return isAuthenticated ? ( + <>{children} + ) : ( + + ); }; export default ProtectedRoute; diff --git a/frontend/src/components/layout/Footer.tsx b/frontend/src/components/layout/Footer.tsx index 97dcf2f..c2652e1 100644 --- a/frontend/src/components/layout/Footer.tsx +++ b/frontend/src/components/layout/Footer.tsx @@ -1,4 +1,6 @@ import React from 'react'; +import { Link } from 'react-router-dom'; +import { ROUTES } from '../../utils/constants'; import './Footer.css'; const Footer: React.FC = () => { @@ -13,10 +15,10 @@ const Footer: React.FC = () => {

Quick Links