diff --git a/.dockerignore b/.dockerignore index 4281df9627..f514654911 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,7 +5,6 @@ back/node_modules front/node_modules nginx/etc/letsencrypt -front/env-config.js front/dist front/dist-ssr .env diff --git a/Dockerfile.front b/Dockerfile.front index ac36771956..f9f719dcb4 100644 --- a/Dockerfile.front +++ b/Dockerfile.front @@ -6,5 +6,4 @@ COPY ./front/ /app/front COPY ./back/src/shared /app/back/src/shared RUN npm run copy-shared RUN npm run build-with-shared-as-is -RUN npm run prod-env-config CMD npm run serve -- --host 0.0.0.0 diff --git a/back/src/__tests__/e2e/addFormEstablishment.e2e.test.ts b/back/src/__tests__/e2e/addFormEstablishment.e2e.test.ts index f97479ad98..7cdb039873 100644 --- a/back/src/__tests__/e2e/addFormEstablishment.e2e.test.ts +++ b/back/src/__tests__/e2e/addFormEstablishment.e2e.test.ts @@ -32,9 +32,7 @@ describe("Route to post addEstablishmentFormRouteWithoutApiKey", () => { it("forbids access to route if no api consumer", async () => { const { request } = await buildTestApp(); - const response = await request - .post(`/immersion-offers`) - .send({}); + const response = await request.post(`/immersion-offers`).send({}); expect(response.status).toBe(403); }); diff --git a/front/.dockerignore b/front/.dockerignore index a1d85a0b5b..f4f9f437c9 100644 --- a/front/.dockerignore +++ b/front/.dockerignore @@ -1,5 +1,4 @@ node_modules -env-config.js .DS_Store dist dist-ssr diff --git a/front/.env b/front/.env deleted file mode 100644 index e1402734b8..0000000000 --- a/front/.env +++ /dev/null @@ -1 +0,0 @@ -GATEWAY=IN_MEMORY diff --git a/front/.env.sample b/front/.env.sample deleted file mode 100644 index 14b4931ea2..0000000000 --- a/front/.env.sample +++ /dev/null @@ -1,5 +0,0 @@ -# .env file is used in a script and can NOT hold any comments -# This file provides explaination and options -# The values that are provided in `.env` file are the default values, the values can be changed at runtime - -GATEWAY=IN_MEMORY # options: IN_MEMORY | HTTP diff --git a/front/.gitignore b/front/.gitignore index b8d35bf7ce..724e0e3964 100644 --- a/front/.gitignore +++ b/front/.gitignore @@ -5,5 +5,3 @@ dist-ssr *.local .idea src/shared -env-config.js -!.env \ No newline at end of file diff --git a/front/env.sh b/front/env.sh deleted file mode 100755 index 6c74eb096d..0000000000 --- a/front/env.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -# This script is from: https://www.freecodecamp.org/news/how-to-implement-runtime-environment-variables-with-create-react-app-docker-and-nginx-7f9d42a91d70/ -# It is used to generate env-config.js. We need it to be able to use env variable at runtime (see link on previous line) - -# Recreate config file -rm -rf ./env-config.js -touch ./env-config.js - -# Add assignment -echo "window._env_ = {" >> ./env-config.js - -# Read each line in .env file -# Each line represents key=value pairs -while read -r line || [[ -n "$line" ]]; -do - # Split env variables by the first character `=` - if printf '%s\n' "$line" | grep -q -e '='; then - varname=$(printf '%s\n' "$line" | sed -e 's/=.*//') - varvalue=$(printf '%s\n' "$line" | sed -e 's/^[^=]*=//') - fi - - # Read value of current variable if exists as Environment variable - value=$(printf '%s\n' "${!varname}") - # Otherwise use value from .env file - [[ -z $value ]] && value=${varvalue} - - # Append configuration property to JS file - echo " $varname: \"$value\"," >> ./env-config.js -done < .env - -echo "}" >> ./env-config.js diff --git a/front/package.json b/front/package.json index f7fc19afa4..2fe9b1cc26 100644 --- a/front/package.json +++ b/front/package.json @@ -2,16 +2,14 @@ "version": "0.0.0", "scripts": { "test": "npm run symlink-or-copy-shared && jest --passWithNoTests", - "dev": "npm run symlink-shared && npm run gen-env-config && vite", - "dev-http": "npm run symlink-shared && GATEWAY=HTTP npm run gen-env-config && vite", + "dev": "npm run symlink-shared && VITE_GATEWAY=IN_MEMORY vite", + "dev-http": "npm run symlink-shared && vite", "build": "npm run symlink-or-copy-shared && vite build", "build-with-shared-as-is": "vite build", - "serve": "npm run prod-env-config && vite preview", + "serve": "vite preview", "typecheck": "tsc --noEmit", "includecheck": "./check_includes.sh", "format": "prettier --write src", - "gen-env-config": "chmod +x ./env.sh && ./env.sh", - "prod-env-config": "npm run gen-env-config && cp env-config.js dist/env-config.js", "format:check": "prettier --check src", "fullcheck": "npm run includecheck && npm run format && npm run test && npm run typecheck", "symlink-or-copy-shared": "if [ ! -z $CI ]; then npm run copy-shared; else npm run symlink-shared; fi;", diff --git a/front/src/app/dependencies.ts b/front/src/app/dependencies.ts index 4bf9a962e4..cfa1a7d09d 100644 --- a/front/src/app/dependencies.ts +++ b/front/src/app/dependencies.ts @@ -22,36 +22,36 @@ import { RomeAutocompleteGateway } from "src/core-logic/ports/RomeAutocompleteGa import { ENV } from "src/environmentVariables"; export const formEstablishmentGateway: FormEstablishmentGateway = - ENV.gateway === "HTTP" - ? new HttpFormEstablishmentGateway() - : new InMemoryFormEstablishmentGateway(["12345678901238"]); + ENV.gateway === "IN_MEMORY" + ? new InMemoryFormEstablishmentGateway(["12345678901238"]) + : new HttpFormEstablishmentGateway(); export const immersionApplicationGateway: ImmersionApplicationGateway = - ENV.gateway === "HTTP" - ? new HttpImmersionApplicationGateway() - : new InMemoryImmersionApplicationGateway(); + ENV.gateway === "IN_MEMORY" + ? new InMemoryImmersionApplicationGateway() + : new HttpImmersionApplicationGateway(); export const immersionSearchGateway: ImmersionSearchGateway = - ENV.gateway === "HTTP" - ? new HttpImmersionSearchGateway() - : new InMemoryImmersionSearchGateway(); + ENV.gateway === "IN_MEMORY" + ? new InMemoryImmersionSearchGateway() + : new HttpImmersionSearchGateway(); export const apiAdresseGateway: ApiAdresseGateway = - ENV.gateway === "HTTP" - ? new HttpApiAdresseGateway() - : new InMemoryApiAdresseGateway(); + ENV.gateway === "IN_MEMORY" + ? new InMemoryApiAdresseGateway() + : new HttpApiAdresseGateway(); export const featureFlagsGateway: FeatureFlagsGateway = - ENV.gateway === "HTTP" - ? new HttpFeatureFlagGateway() - : new InMemoryFeatureFlagGateway(); + ENV.gateway === "IN_MEMORY" + ? new InMemoryFeatureFlagGateway() + : new HttpFeatureFlagGateway(); export const agencyGateway: AgencyGateway = - ENV.gateway === "HTTP" - ? new HttpAgencyGateway() - : new InMemoryAgencyGateway(); + ENV.gateway === "IN_MEMORY" + ? new InMemoryAgencyGateway() + : new HttpAgencyGateway(); export const romeAutocompleteGateway: RomeAutocompleteGateway = - ENV.gateway === "HTTP" - ? new HttpRomeAutocompleteGateway() - : new InMemoryRomeAutocompleteGateway(); + ENV.gateway === "IN_MEMORY" + ? new InMemoryRomeAutocompleteGateway() + : new HttpRomeAutocompleteGateway(); diff --git a/front/src/environmentVariables.ts b/front/src/environmentVariables.ts index 3911caea9f..15a50aa9d3 100644 --- a/front/src/environmentVariables.ts +++ b/front/src/environmentVariables.ts @@ -1,12 +1,7 @@ -import { throwIfNotInArray } from "src/shared/envHelpers"; +const gateway = + import.meta.env.VITE_GATEWAY === "IN_MEMORY" ? "IN_MEMORY" : "HTTP"; -const windowEnv = (window as any)._env_; - -const gateway = throwIfNotInArray({ - processEnv: windowEnv, - authorizedValues: ["HTTP", "IN_MEMORY"], - variableName: "GATEWAY", -}); +console.info("Gateway is : ", gateway); export const ENV = { dev: import.meta.env.DEV,