diff --git a/Dockerfile.local b/Dockerfile.local new file mode 100644 index 0000000000000000000000000000000000000000..c8e9a4fc315b19ae97afc9b8c051e3175aeee7bc --- /dev/null +++ b/Dockerfile.local @@ -0,0 +1,21 @@ +# Stage 1, based on Nginx, to have only the compiled app, ready for production with Nginx +FROM nginx:1.16 +COPY ./nginx/nginx.conf /etc/nginx/nginx.conf +COPY ./nginx/site.prod.conf /etc/nginx/conf.d/default.conf +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] + +# Stage 0, "build-stage", based on Node.js, to build and compile the frontend +FROM node:14-alpine as build-stage + +WORKDIR /app +# install app dependencies +COPY package*.json ./ +RUN npm install + +# add app +COPY . ./ + +# start app +CMD ["npm", "start"] + diff --git a/README.md b/README.md index 669108c2a8c2d115ac14b12bbacbca2fc5bc21b0..cfd87aae98207723472c18c48b315da0f2adcccd 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,19 @@ # Client - LLLE Projet client du backoffice LLLE + ## Local usage +In order to launch the projet in local with the backend working launch the following command + +```bash +yarn docker-local-up +``` + +To stop it properly use + ```bash -docker-compose up -d -``` \ No newline at end of file +yarn docker-local-down +``` + +The nginx server handles https request and responses from the backend diff --git a/docker-compose.local.yml b/docker-compose.local.yml index c93ac0c174fa766eedc21381257910bb89a17f0e..f9f0b99f8843cc9f4ec2ee393d73c8220c2f60c9 100644 --- a/docker-compose.local.yml +++ b/docker-compose.local.yml @@ -4,13 +4,18 @@ services: container_name: front build: context: . - dockerfile: Dockerfile + dockerfile: Dockerfile.local depends_on: - database: - condition: service_healthy + - nginx volumes: - - '/app' + - '.:/app' - '/app/node_modules' + ports: + - 3000:3000 + + nginx: + image: nginx:1.16 + volumes: - ./nginx/nginx.conf:/etc/nginx/nginx.conf - ./nginx/site.conf:/etc/nginx/conf.d/default.conf - ./cert.pem:/etc/nginx/cert.pem diff --git a/nginx/site.conf b/nginx/site.conf index 5849a845c06c75581d97e1927485b2f522e5f828..8e57664ce0b020f9ca42b0f1fe0d7410e4490697 100644 --- a/nginx/site.conf +++ b/nginx/site.conf @@ -6,10 +6,8 @@ server { ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5; - location / { - root /usr/share/nginx/html; - index index.html index.htm; - try_files $uri $uri/ /index.html =404; + location / { + proxy_pass https://front; } location /api { proxy_pass https://backend:1443/api; @@ -20,6 +18,7 @@ server { location /OAuth2Callback { proxy_pass https://backend:1443/OAuth2Callback; } + location /Logout { proxy_pass https://backend:1443/Logout; } diff --git a/package.json b/package.json index 291c5b0875db9876ebdc5e2ef450f1d5d442e042..1352e11dd709b6bf947602e1e575fc3fe9a64ac0 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "private": true, "scripts": { - "start": "react-scripts start", + "start": "set PORT=443 && react-scripts start", "build": "react-scripts build", "docker-local-up" : "docker-compose -f docker-compose.local.yml up", "docker-local-down" : "docker-compose -f docker-compose.local.yml down", diff --git a/src/hooks/useAuth.ts b/src/hooks/useAuth.ts index 656444a218da031dccbec675dcca9c5a25345c78..d27df2704cec182cc025faf958c27b4784398f33 100644 --- a/src/hooks/useAuth.ts +++ b/src/hooks/useAuth.ts @@ -16,7 +16,7 @@ export const useAuth = (): Auth => { //login user const loginUser = async (): Promise<void> => { try { - window.location.href="/OAuth2Login" + window.location.href = '/OAuth2Login' await setUserContext() } catch (e) { setError(e) @@ -26,7 +26,7 @@ export const useAuth = (): Auth => { const logoutUser = async (): Promise<void> => { try { if (setUser) setUser(null) - window.location.href="/Logout" + window.location.href = '/Logout' } catch (e) { setError(e) }