From f6c859f9b2660ee5ff9b5c9c30fcc0cd2475b94b Mon Sep 17 00:00:00 2001 From: lcross2002 <liamdcross@outlook.com> Date: Tue, 12 Mar 2024 22:16:19 +0000 Subject: [PATCH] client using nginx --- client/Dockerfile | 14 ++++++++++---- client/nginx.conf | 25 +++++++++++++++++++++++++ client/src/services/Api/Api.ts | 2 +- docker-compose.yaml | 2 +- 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 client/nginx.conf diff --git a/client/Dockerfile b/client/Dockerfile index 9f2a70d..cccc489 100644 --- a/client/Dockerfile +++ b/client/Dockerfile @@ -1,8 +1,8 @@ -FROM node:18-alpine +FROM node:18-alpine AS build WORKDIR /app -COPY package.json . +COPY package.json package-lock.json ./ RUN npm install @@ -10,6 +10,12 @@ COPY . . RUN npm run build -EXPOSE 8080 +FROM nginx:alpine -CMD [ "npm", "run", "preview" ] \ No newline at end of file +COPY --from=build /app/dist /usr/share/nginx/html + +COPY nginx.conf /etc/nginx/nginx.conf + +EXPOSE 4200 + +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/client/nginx.conf b/client/nginx.conf new file mode 100644 index 0000000..59ed87c --- /dev/null +++ b/client/nginx.conf @@ -0,0 +1,25 @@ +# nginx.conf + +events {} + +http { + server { + listen 4200; + server_name localhost; + + root /usr/share/nginx/html; + index index.html; + + types { + text/html html; + application/javascript js; + text/css css; + image/png png; + image/jpeg jpg; + } + + location / { + try_files $uri $uri/ /index.html; + } + } +} \ No newline at end of file diff --git a/client/src/services/Api/Api.ts b/client/src/services/Api/Api.ts index f6c6874..2b25581 100644 --- a/client/src/services/Api/Api.ts +++ b/client/src/services/Api/Api.ts @@ -1,5 +1,5 @@ import axios from 'axios'; -import { redirect } from 'react-router-dom'; +// import { redirect } from 'react-router-dom'; export interface IFact { fact: string; diff --git a/docker-compose.yaml b/docker-compose.yaml index 36dcf8a..1c0d483 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -6,7 +6,7 @@ services: context: client dockerfile: ./Dockerfile ports: - - 8080-8080 + - 4200-4200 networks: - airline-net # End React UI Client -- GitLab