diff --git a/Dockerfile b/Dockerfile index f28015b..b73025e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,23 @@ -FROM node:20.18.0 +# Stage 1: Build the React app +FROM node:20.18.0 AS build -# Set the working directory WORKDIR /app - -# Copy package.json and package-lock.json to the working directory -COPY package*.json ./ +COPY . . # Install dependencies RUN npm install -# Copy the rest of the application code to the working directory -COPY . . +# Use environment variables for the build +ARG REACT_APP_API_SERVICE_URL +ENV REACT_APP_API_SERVICE_URL=${REACT_APP_API_SERVICE_URL} -# Build the React app +# Build the app RUN npm run build -# Install serve to serve the build folder -RUN npm install -g serve - -# Set the command to run the app -CMD ["serve", "-s", "build"] +# Stage 2: Serve with Nginx +FROM nginx:alpine +COPY --from=build /app/build /usr/share/nginx/html +COPY nginx.conf /etc/nginx/conf.d/default.conf -# Expose the port the app runs on -EXPOSE 5000 \ No newline at end of file +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..005edd3 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,12 @@ +version: '3' +services: + movies-app-client: + build: + context: . + dockerfile: Dockerfile + args: + REACT_APP_API_SERVICE_URL: ${REACT_APP_API_SERVICE_URL} + ports: + - "3000:80" + env_file: + - .env diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..72ef8ca --- /dev/null +++ b/nginx.conf @@ -0,0 +1,9 @@ +server { + listen 80; + + location / { + root /usr/share/nginx/html; + index index.html; + try_files $uri /index.html; + } +} diff --git a/package.json b/package.json index 22daaf2..a50fcf8 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "@testing-library/user-event": "^13.2.1", "axios": "^1.3.2", "dayjs": "^1.11.7", + "dotenv": "^16.4.5", "formik": "^2.2.9", "query-string": "^8.1.0", "react": "^18.2.0", @@ -51,4 +52,4 @@ "last 1 safari version" ] } -} +} \ No newline at end of file diff --git a/src/api/client/public.client.js b/src/api/client/public.client.js index e593867..24a8427 100644 --- a/src/api/client/public.client.js +++ b/src/api/client/public.client.js @@ -3,6 +3,9 @@ import queryString from "query-string"; const baseURL = process.env.REACT_APP_API_SERVICE_URL; +console.log({ baseURL }); + + const publicClient = axios.create({ baseURL, paramsSerializers: { diff --git a/yarn.lock b/yarn.lock index 3b3c521..e95f5ce 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4065,6 +4065,11 @@ dotenv@^10.0.0: resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81" integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q== +dotenv@^16.4.5: + version "16.4.5" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.5.tgz#cdd3b3b604cb327e286b4762e13502f717cb099f" + integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg== + duplexer@^0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/duplexer/-/duplexer-0.1.2.tgz#3abe43aef3835f8ae077d136ddce0f276b0400e6"