Skip to content

Commit

Permalink
remove complicated and useless frontend env variable management
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeBu committed Mar 28, 2022
1 parent 7244e67 commit e9035b9
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 79 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ back/node_modules
front/node_modules

nginx/etc/letsencrypt
front/env-config.js
front/dist
front/dist-ssr
.env
Expand Down
1 change: 0 additions & 1 deletion Dockerfile.front
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 1 addition & 3 deletions back/src/__tests__/e2e/addFormEstablishment.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
1 change: 0 additions & 1 deletion front/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules
env-config.js
.DS_Store
dist
dist-ssr
Expand Down
1 change: 0 additions & 1 deletion front/.env

This file was deleted.

5 changes: 0 additions & 5 deletions front/.env.sample

This file was deleted.

2 changes: 0 additions & 2 deletions front/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ dist-ssr
*.local
.idea
src/shared
env-config.js
!.env
31 changes: 0 additions & 31 deletions front/env.sh

This file was deleted.

8 changes: 3 additions & 5 deletions front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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;",
Expand Down
42 changes: 21 additions & 21 deletions front/src/app/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
11 changes: 3 additions & 8 deletions front/src/environmentVariables.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit e9035b9

Please sign in to comment.