From f950d96d0908fda654184ba66e8fc6985b653da7 Mon Sep 17 00:00:00 2001 From: Benoit Serrano Date: Thu, 24 Oct 2024 15:47:27 +0200 Subject: [PATCH] use window origin instead of var env --- src/client/package-lock.json | 3 +-- src/client/package.json | 9 ++++----- .../src/components/DropDownLogout/DropDownLogout.tsx | 2 -- src/client/src/components/Header/Header.tsx | 3 +-- src/client/src/config.ts | 5 ----- src/client/src/lib/api.ts | 5 ++--- src/index.ts | 1 + 7 files changed, 9 insertions(+), 19 deletions(-) delete mode 100644 src/client/src/config.ts diff --git a/src/client/package-lock.json b/src/client/package-lock.json index 338ab00..bd1bcba 100644 --- a/src/client/package-lock.json +++ b/src/client/package-lock.json @@ -26,8 +26,7 @@ "serve": "^14.2.3", "typescript": "^5.2.2", "vite": "^5.2.0" - }, - "devDependencies": {} + } }, "node_modules/@ampproject/remapping": { "version": "2.3.0", diff --git a/src/client/package.json b/src/client/package.json index 16df2a8..b3cfdbf 100644 --- a/src/client/package.json +++ b/src/client/package.json @@ -14,10 +14,8 @@ "start": "serve --single dist" }, "dependencies": { - "@tanstack/react-query": "^5.59.15", - "react-lottie": "^1.2.4", - "serve": "^14.2.3", "@codegouvfr/react-dsfr": "^1.9.27", + "@tanstack/react-query": "^5.59.15", "@types/js-cookie": "^3.0.6", "@types/react": "^18.2.66", "@types/react-dom": "^18.2.22", @@ -27,10 +25,11 @@ "prettier": "^3.3.3", "react": "^18.2.0", "react-dom": "^18.2.0", + "react-lottie": "^1.2.4", "react-router-dom": "^6.23.1", "react-scroll": "^1.9.0", + "serve": "^14.2.3", "typescript": "^5.2.2", "vite": "^5.2.0" - }, - "devDependencies": {} + } } diff --git a/src/client/src/components/DropDownLogout/DropDownLogout.tsx b/src/client/src/components/DropDownLogout/DropDownLogout.tsx index 7829e01..fc55d1a 100644 --- a/src/client/src/components/DropDownLogout/DropDownLogout.tsx +++ b/src/client/src/components/DropDownLogout/DropDownLogout.tsx @@ -1,10 +1,8 @@ import { useEffect, useState } from "react"; import { getUserInfo } from "../../lib/authentication"; -import { config } from "../../config"; export function DropDownLogout() { const [width, setWidth] = useState(window.innerWidth); - console.log(config); useEffect(() => { const handleResize = () => setWidth(window.innerWidth); window.addEventListener("resize", handleResize); diff --git a/src/client/src/components/Header/Header.tsx b/src/client/src/components/Header/Header.tsx index 5c606f7..3954e6b 100644 --- a/src/client/src/components/Header/Header.tsx +++ b/src/client/src/components/Header/Header.tsx @@ -2,7 +2,6 @@ import { Header as DsfrHeader } from "@codegouvfr/react-dsfr/Header"; import NameChangeNotice from "./NameChangeNotice"; import { getUserInfo } from "../../lib/authentication"; import { DropDownLogout } from "../DropDownLogout/DropDownLogout"; -import { config } from "../../config"; function Header() { const userInfo = getUserInfo(); @@ -29,7 +28,7 @@ function Header() { iconId: "fr-icon-account-circle-line" as const, linkProps: { target: "_self", - to: `${config.API_URL}/openid/authorize`, + to: `${window.location.origin}/openid/authorize`, }, text: "Se connecter", }, diff --git a/src/client/src/config.ts b/src/client/src/config.ts deleted file mode 100644 index aebab81..0000000 --- a/src/client/src/config.ts +++ /dev/null @@ -1,5 +0,0 @@ -const config = { - API_URL: process.env.REACT_APP_API_URL || "http://localhost:3001", -}; - -export { config }; diff --git a/src/client/src/lib/api.ts b/src/client/src/lib/api.ts index d5bbeac..183fe79 100644 --- a/src/client/src/lib/api.ts +++ b/src/client/src/lib/api.ts @@ -1,9 +1,8 @@ -import { config } from "../config"; - const api = { me }; async function me() { - const response = await fetch(`${config.API_URL}/api/me`); + const BASE_URL = window.location.origin; + const response = await fetch(`${BASE_URL}/api/me`); return response.json(); } diff --git a/src/index.ts b/src/index.ts index f1023b4..0afc29c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,6 +45,7 @@ app.get("/openid/authorize", async (req, res) => { acr_values, nonce, state, + redirect_uri: `${config.HOST_URL}/openid/oidc-callback`, claims: { id_token: { amr: {