diff --git a/.gitignore b/.gitignore index 3cf52cc..655dcc6 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ dist-ssr *.njsproj *.sln *.sw? + +.env diff --git a/docker-compose.yaml b/docker-compose.yaml index 5d79ca8..2a905fc 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,5 +1,3 @@ -version: '3.8' - services: db: image: postgres:15 @@ -37,8 +35,11 @@ services: - app-network frontend: - build: ./frontend - env_file: ./.env + build: + context: ./frontend + args: + VITE_API_URL: ${API_URL} + ports: - "3000:80" depends_on: diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 4321151..c3f5271 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,15 +1,14 @@ -# Build stage -FROM node:20 AS build +FROM node:20 AS builder WORKDIR /app COPY package*.json ./ RUN npm install COPY . . +ARG VITE_API_URL +ENV VITE_API_URL=$VITE_API_URL RUN npm run build -# Production stage -FROM nginx:alpine -COPY nginx.conf /etc/nginx/nginx.conf -COPY --from=build /app/dist /usr/share/nginx/html - -EXPOSE 80 -CMD ["nginx", "-g", "daemon off;"] +FROM node:20-alpine +WORKDIR /app +COPY --from=builder /app ./ +EXPOSE 3000 +CMD ["npx", "vite", "--port", "3000"] diff --git a/frontend/nginx.conf b/frontend/nginx.conf deleted file mode 100644 index 3f8a88c..0000000 --- a/frontend/nginx.conf +++ /dev/null @@ -1,28 +0,0 @@ -worker_processes 1; - -events { worker_connections 1024; } - -http { - include mime.types; - default_type application/octet-stream; - sendfile on; - keepalive_timeout 65; - - server { - listen 80; - server_name _; - - root /usr/share/nginx/html; - index index.html; - - location / { - # try to serve file directly, otherwise fallback to index.html - try_files $uri $uri/ /index.html; - } - - # optional: block .git, .env, etc - location ~ /\.(?!well-known).* { - deny all; - } - } -} diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 4636add..210dbcb 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -31,9 +31,7 @@ import { } from "react-icons/fa"; import type { Blog } from "./utils/types"; import { countWords } from "./utils/countWords"; - -// Base API URL from env -const API_URL = import.meta.env.VITE_API_URL || "http://localhost:8000"; +import { API_URL } from "./utils/constants"; // Auth Context interface AuthContextProps { diff --git a/frontend/src/utils/BlogList.tsx b/frontend/src/utils/BlogList.tsx index 5e441b7..29c30b7 100644 --- a/frontend/src/utils/BlogList.tsx +++ b/frontend/src/utils/BlogList.tsx @@ -1,9 +1,10 @@ import { useState, useEffect } from "react"; +import { API_URL } from "./constants"; export function BlogList() { const [content, setContent] = useState(""); useEffect(() => { - fetch(`localhost:8000/get-blogs`) + fetch(`${API_URL}/get-blogs`) .then((res) => res.text()) .then(setContent); }, []);