diff --git a/codewit/api/src/main.ts b/codewit/api/src/main.ts index d1c0e79..dab9305 100644 --- a/codewit/api/src/main.ts +++ b/codewit/api/src/main.ts @@ -10,7 +10,7 @@ import userRouter from './routes/user'; import attemptRouter from './routes/attempt'; import passport from 'passport'; import session from 'express-session'; -import { COOKIE_KEY, HOST, PORT, REDIS_HOST, REDIS_PORT } from './secrets'; +import { COOKIE_KEY, HOST, PORT } from './secrets'; import './auth/passport'; import { checkAuth } from './middleware/auth'; import { catchError, asyncHandle } from "./middleware/catch"; diff --git a/codewit/api/src/secrets.ts b/codewit/api/src/secrets.ts index c27bddc..5b6762b 100644 --- a/codewit/api/src/secrets.ts +++ b/codewit/api/src/secrets.ts @@ -1,7 +1,5 @@ const HOST = process.env.API_HOST ?? '0.0.0.0'; const PORT = process.env.PORT ? Number(process.env.PORT) : 3000; -const REDIS_HOST = process.env.REDIS_HOST ?? 'localhost'; -const REDIS_PORT = process.env.REDIS_PORT ? Number(process.env.REDIS_PORT) : 6379; const GOOGLE_CLIENT_ID = process.env.GOOGLE_CLIENT_ID; const GOOGLE_CLIENT_SECRET = process.env.GOOGLE_CLIENT_SECRET; const GOOGLE_REDIRECT_URL = process.env.GOOGLE_REDIRECT_URL; @@ -11,8 +9,6 @@ const FRONTEND_URL = process.env.FRONTEND_URL; export { HOST, PORT, - REDIS_HOST, - REDIS_PORT, GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, GOOGLE_REDIRECT_URL, diff --git a/codewit/client/vite.config.ts b/codewit/client/vite.config.ts index c533e8f..a08b6d7 100644 --- a/codewit/client/vite.config.ts +++ b/codewit/client/vite.config.ts @@ -8,13 +8,22 @@ dotenv.config({ path: '../../.env' }); const API_PORT = process.env.API_PORT; const API_HOST = process.env.API_HOST; +const CODEEVAL_PORT = process.env.CODEEVAL_PORT; +const CODEEVAL_HOST = process.env.CODEEVAL_HOST; +const resolveTarget = ( + host: string | undefined, + port: string | undefined, + fallback: string +) => (host ? `http://${host}${port ? `:${port}` : ''}` : fallback); const API_TARGET = API_HOST - ? `http://${API_HOST}${API_PORT ? `:${API_PORT}` : ''}` + ? resolveTarget(API_HOST, API_PORT, 'http://localhost:3000') : 'http://localhost:3000'; -const CODEEVAL_TARGET = API_HOST - ? `http://${API_HOST}${API_PORT ? `:${API_PORT}` : ''}` - : 'http://localhost:3002'; -const usingGatewayProxy = Boolean(API_HOST); +const CODEEVAL_TARGET = CODEEVAL_HOST + ? resolveTarget(CODEEVAL_HOST, CODEEVAL_PORT, 'http://localhost:3002') + : API_HOST + ? API_TARGET + : 'http://localhost:3002'; +const usingGatewayProxy = Boolean(API_HOST) && !CODEEVAL_HOST; export default defineConfig(({ mode }) => ({ root: __dirname, @@ -47,12 +56,16 @@ export default defineConfig(({ mode }) => ({ '/api': { target: API_TARGET, changeOrigin: true, - rewrite: usingGatewayProxy ? undefined : (path) => path.replace(/^\/api/, ''), + rewrite: usingGatewayProxy + ? undefined + : (path) => path.replace(/^\/api/, ''), }, '/codeeval': { target: CODEEVAL_TARGET, changeOrigin: true, - rewrite: usingGatewayProxy ? undefined : (path) => path.replace(/^\/codeeval/, ''), + rewrite: usingGatewayProxy + ? undefined + : (path) => path.replace(/^\/codeeval/, ''), }, }, }, diff --git a/codewit/docker-compose.yml b/codewit/docker-compose.yml index 8a262f6..50f4261 100644 --- a/codewit/docker-compose.yml +++ b/codewit/docker-compose.yml @@ -29,10 +29,8 @@ services: - DB_PASSWORD=12345 - DB_NAME=codewitus_db - DB_PORT=5432 - - API_PORT=3000 - - REDIS_HOST=redis - - REDIS_PORT=6379 - - FRONTEND_URL=http://localhost:80 + - PORT=3000 + - FRONTEND_URL=http://localhost:3001 - NODE_ENV=dev env_file: - .env @@ -108,8 +106,10 @@ services: target: /codewit/lib/ action: sync environment: - - API_PORT=80 - - API_HOST=nginx + - API_HOST=app + - API_PORT=3000 + - CODEEVAL_HOST=codeeval + - CODEEVAL_PORT=3002 networks: - codewitus stdin_open: true @@ -129,38 +129,12 @@ services: environment: - HOST=0.0.0.0 - PORT=3002 - - REDIS_HOST=redis - - REDIS_PORT=6379 - ENABLE_CPP=true ports: - 3002:3002 networks: - codewitus - nginx: - depends_on: - - frontend - - app - - codewitus_db - image: nginx:latest - restart: unless-stopped - ports: - - 80:80 - volumes: - - ./nginx.conf:/etc/nginx/nginx.conf:ro - networks: - - codewitus - stdin_open: true - tty: true - - redis: - image: redis:7.4-alpine - restart: unless-stopped - ports: - - 6379:6379 - networks: - - codewitus - networks: codewitus: driver: bridge diff --git a/codewit/nginx.conf b/codewit/nginx.conf deleted file mode 100644 index 571b15b..0000000 --- a/codewit/nginx.conf +++ /dev/null @@ -1,33 +0,0 @@ -events {} - -http { - server { - listen 80; - - location / { - proxy_pass http://frontend:3001; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - } - - location /api { - proxy_pass http://app:3000; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - - rewrite ^/api(/.*)?$ $1 break; - } - - location /codeeval { - proxy_pass http://codeeval:3002; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header Cookie $http_cookie; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - - rewrite ^/codeeval/?(.*)$ /$1 break; - } - } -}