From 69a1504704aade080edf8b205495edbae6cc84a3 Mon Sep 17 00:00:00 2001 From: "guilhem.carron" <gcarron@grandlyon.com> Date: Tue, 10 Aug 2021 09:45:39 +0200 Subject: [PATCH] test --- docker-compose.yml | 4 ++-- public/index.html | 1 + src/App.tsx | 2 +- src/hooks/useAuth.ts | 17 +++++++++------- src/hooks/useFindUser.ts | 5 +++-- src/services/monthlyNews.service.ts | 30 +++++++++++++---------------- 6 files changed, 30 insertions(+), 29 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 758d10b9..03b47b9b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3.7' services: nginx: - image: registry.forge.grandlyon.com/web-et-numerique/llle_project/backoffice-client:dev + image: test 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:dev + image: registry.forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server:back networks: backoffice: depends_on: diff --git a/public/index.html b/public/index.html index f7cd1670..155760c8 100644 --- a/public/index.html +++ b/public/index.html @@ -1,6 +1,7 @@ <!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 2495ec0a..ba353aff 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -10,7 +10,7 @@ function App() { const { user, setUser, isLoading } = useFindUser() return ( - <BrowserRouter> + <BrowserRouter basename={process.env.PUBLIC_URL}> <UserContext.Provider value={{ user, setUser, isLoading }}> <Layout> <Routes /> diff --git a/src/hooks/useAuth.ts b/src/hooks/useAuth.ts index 5033ce15..4bc30ac1 100644 --- a/src/hooks/useAuth.ts +++ b/src/hooks/useAuth.ts @@ -3,8 +3,6 @@ import axios from 'axios' import { UserContext } from './userContext' import { useHistory } from 'react-router-dom' -const _apiUrl: string = 'https://localhost:443/' - export interface Auth { loginUser: () => Promise<void> error: null @@ -18,7 +16,9 @@ export const useAuth = (): Auth => { //login user const loginUser = async (): Promise<void> => { try { - await axios.get(`${_apiUrl}OAuth2Login`, { withCredentials: true }) + await axios.get(`${process.env.PUBLIC_URL}OAuth2Login`, { + withCredentials: true, + }) await setUserContext() } catch (e) { setError(e) @@ -28,7 +28,7 @@ export const useAuth = (): Auth => { const logoutUser = async (): Promise<void> => { try { if (setUser) setUser(null) - await axios.get(`${_apiUrl}Logout`) + await axios.get(`${process.env.PUBLIC_URL}Logout`) } catch (e) { setError(e) } @@ -37,9 +37,12 @@ export const useAuth = (): Auth => { //set user in context and push them home const setUserContext = async (): Promise<void> => { try { - const { data } = await axios.get(`${_apiUrl}api/common/WhoAmI`, { - withCredentials: true, - }) + const { data } = await axios.get( + `${process.env.PUBLIC_URL}api/common/WhoAmI`, + { + withCredentials: true, + } + ) if (data && setUser) { setUser(data) history.push('/editing') diff --git a/src/hooks/useFindUser.ts b/src/hooks/useFindUser.ts index 2d3ae849..8e1f51c8 100644 --- a/src/hooks/useFindUser.ts +++ b/src/hooks/useFindUser.ts @@ -5,11 +5,12 @@ import { User } from '../models/user.model' const useFindUser = () => { const [user, setUser] = useState<User | null>(null) const [isLoading, setLoading] = useState<boolean>(true) - const _apiUrl: string = 'https://localhost:443/' useEffect(() => { async function findUser() { - const { data } = await axios.get(`${_apiUrl}api/common/WhoAmI`) + const { data } = await axios.get( + `${process.env.PUBLIC_URL}api/common/WhoAmI` + ) if (data) { setUser(data) setLoading(false) diff --git a/src/services/monthlyNews.service.ts b/src/services/monthlyNews.service.ts index 2185f2a0..417519ac 100644 --- a/src/services/monthlyNews.service.ts +++ b/src/services/monthlyNews.service.ts @@ -21,7 +21,7 @@ export class MonthlyNewsService { ): Promise<void> => { try { await axios.put( - `${this._apiUrl}api/admin/monthlyNews`, + `${process.env.PUBLIC_URL}/api/admin/monthlyNews`, { month: date.getMonth(), year: date.getFullYear(), @@ -51,17 +51,13 @@ export class MonthlyNewsService { ): Promise<IMonthlyNews | null> => { try { const { data } = await axios.get( - `${this._apiUrl}api/admin/monthlyNews/${year}/${month}`, + `${process.env.PUBLIC_URL}/api/admin/monthlyNews/${year}/${month}`, { headers: { 'XSRF-TOKEN': token, }, } ) - // if (data == {}) { - // return null - // } - return data as IMonthlyNews } catch (e) { console.log('error', e) @@ -79,16 +75,13 @@ export class MonthlyNewsService { ): Promise<IPoll | null> => { try { const { data } = await axios.get( - `${this._apiUrl}api/admin/poll/${year}/${month}`, + `${process.env.PUBLIC_URL}/api/admin/poll/${year}/${month}`, { headers: { 'XSRF-TOKEN': token, }, } ) - // if (data === {}) { - // return null - // } return data as IPoll } catch (e) { console.log('error', e) @@ -110,7 +103,7 @@ export class MonthlyNewsService { ): Promise<void> => { try { await axios.put( - `${this._apiUrl}api/admin/poll`, + `${process.env.PUBLIC_URL}/api/admin/poll`, { month: date.getMonth(), year: date.getFullYear(), @@ -141,11 +134,14 @@ export class MonthlyNewsService { token: string ): Promise<void> => { try { - await axios.delete(`${this._apiUrl}api/admin/poll/${year}/${month}`, { - headers: { - 'XSRF-TOKEN': token, - }, - }) + await axios.delete( + `${process.env.PUBLIC_URL}api/admin/poll/${year}/${month}`, + { + headers: { + 'XSRF-TOKEN': token, + }, + } + ) toast.success('Poll succesfully deleted !') } catch (e) { toast.error('Failed to delete poll') @@ -165,7 +161,7 @@ export class MonthlyNewsService { ): Promise<void> => { try { await axios.delete( - `${this._apiUrl}api/admin/monthlyNews/${year}/${month}`, + `${process.env.PUBLIC_URL}api/admin/monthlyNews/${year}/${month}`, { headers: { 'XSRF-TOKEN': token, -- GitLab