From ecd88441a45d1139ed4faafe62bf0c296dfce0bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Pailharey?= <rpailharey@grandlyon.com> Date: Tue, 10 Aug 2021 15:38:20 +0200 Subject: [PATCH] refactor: deleted baseurl variable + added swagger routes to nginx conf --- docker-compose.yml | 4 ++-- nginx/site.conf | 3 +++ public/index.html | 1 - src/App.tsx | 2 +- src/hooks/useAuth.ts | 13 +++---------- src/hooks/useFindUser.ts | 4 +--- src/services/monthlyNews.service.ts | 17 +++++++---------- 7 files changed, 17 insertions(+), 27 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 03b47b9b..3bc5babf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3.7' services: nginx: - image: test + image: registry.forge.grandlyon.com/web-et-numerique/llle_project/backoffice-client:no-baseurl restart: unless-stopped ports: - 443:443 @@ -29,7 +29,7 @@ services: retries: 60 backend: - image: registry.forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server:back + image: registry.forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server:no-cors networks: backoffice: depends_on: diff --git a/nginx/site.conf b/nginx/site.conf index e6d27c77..a15e8627 100644 --- a/nginx/site.conf +++ b/nginx/site.conf @@ -23,4 +23,7 @@ server { location /Logout { proxy_pass https://backend:1443/Logout; } + location /swagger { + proxy_pass https://backend:1443/swagger; + } } diff --git a/public/index.html b/public/index.html index 155760c8..f7cd1670 100644 --- a/public/index.html +++ b/public/index.html @@ -1,7 +1,6 @@ <!DOCTYPE html> <html lang="en"> <head> - <base href="%PUBLIC_URL%/"> <meta charset="utf-8" /> <link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> diff --git a/src/App.tsx b/src/App.tsx index ba353aff..2495ec0a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -10,7 +10,7 @@ function App() { const { user, setUser, isLoading } = useFindUser() return ( - <BrowserRouter basename={process.env.PUBLIC_URL}> + <BrowserRouter> <UserContext.Provider value={{ user, setUser, isLoading }}> <Layout> <Routes /> diff --git a/src/hooks/useAuth.ts b/src/hooks/useAuth.ts index 4bc30ac1..656444a2 100644 --- a/src/hooks/useAuth.ts +++ b/src/hooks/useAuth.ts @@ -16,9 +16,7 @@ export const useAuth = (): Auth => { //login user const loginUser = async (): Promise<void> => { try { - await axios.get(`${process.env.PUBLIC_URL}OAuth2Login`, { - withCredentials: true, - }) + window.location.href="/OAuth2Login" await setUserContext() } catch (e) { setError(e) @@ -28,7 +26,7 @@ export const useAuth = (): Auth => { const logoutUser = async (): Promise<void> => { try { if (setUser) setUser(null) - await axios.get(`${process.env.PUBLIC_URL}Logout`) + window.location.href="/Logout" } catch (e) { setError(e) } @@ -37,12 +35,7 @@ export const useAuth = (): Auth => { //set user in context and push them home const setUserContext = async (): Promise<void> => { try { - const { data } = await axios.get( - `${process.env.PUBLIC_URL}api/common/WhoAmI`, - { - withCredentials: true, - } - ) + const { data } = await axios.get(`/api/common/WhoAmI`) if (data && setUser) { setUser(data) history.push('/editing') diff --git a/src/hooks/useFindUser.ts b/src/hooks/useFindUser.ts index 8e1f51c8..3c853bca 100644 --- a/src/hooks/useFindUser.ts +++ b/src/hooks/useFindUser.ts @@ -8,9 +8,7 @@ const useFindUser = () => { useEffect(() => { async function findUser() { - const { data } = await axios.get( - `${process.env.PUBLIC_URL}api/common/WhoAmI` - ) + const { data } = await axios.get(`/api/common/WhoAmI`) if (data) { setUser(data) setLoading(false) diff --git a/src/services/monthlyNews.service.ts b/src/services/monthlyNews.service.ts index 417519ac..dc1f9571 100644 --- a/src/services/monthlyNews.service.ts +++ b/src/services/monthlyNews.service.ts @@ -3,10 +3,7 @@ import { IMonthlyNews } from '../models/monthlyNews.model' import { IPoll } from '../models/poll.model' import { toast } from 'react-toastify' export class MonthlyNewsService { - private readonly _apiUrl: string - constructor() { - this._apiUrl = 'https://localhost:443/' - } + /** * Creates a quotation and header for selected month * @param date @@ -21,7 +18,7 @@ export class MonthlyNewsService { ): Promise<void> => { try { await axios.put( - `${process.env.PUBLIC_URL}/api/admin/monthlyNews`, + `/api/admin/monthlyNews`, { month: date.getMonth(), year: date.getFullYear(), @@ -51,7 +48,7 @@ export class MonthlyNewsService { ): Promise<IMonthlyNews | null> => { try { const { data } = await axios.get( - `${process.env.PUBLIC_URL}/api/admin/monthlyNews/${year}/${month}`, + `/api/admin/monthlyNews/${year}/${month}`, { headers: { 'XSRF-TOKEN': token, @@ -75,7 +72,7 @@ export class MonthlyNewsService { ): Promise<IPoll | null> => { try { const { data } = await axios.get( - `${process.env.PUBLIC_URL}/api/admin/poll/${year}/${month}`, + `/api/admin/poll/${year}/${month}`, { headers: { 'XSRF-TOKEN': token, @@ -103,7 +100,7 @@ export class MonthlyNewsService { ): Promise<void> => { try { await axios.put( - `${process.env.PUBLIC_URL}/api/admin/poll`, + `/api/admin/poll`, { month: date.getMonth(), year: date.getFullYear(), @@ -135,7 +132,7 @@ export class MonthlyNewsService { ): Promise<void> => { try { await axios.delete( - `${process.env.PUBLIC_URL}api/admin/poll/${year}/${month}`, + `/api/admin/poll/${year}/${month}`, { headers: { 'XSRF-TOKEN': token, @@ -161,7 +158,7 @@ export class MonthlyNewsService { ): Promise<void> => { try { await axios.delete( - `${process.env.PUBLIC_URL}api/admin/monthlyNews/${year}/${month}`, + `/api/admin/monthlyNews/${year}/${month}`, { headers: { 'XSRF-TOKEN': token, -- GitLab