From 80c79ceb3fa7c7e74efe3cba4f21eb8bcc07b4da Mon Sep 17 00:00:00 2001 From: "Felix T.J. Dietrich" Date: Tue, 13 Aug 2024 17:51:08 +0200 Subject: [PATCH] fix env --- webapp/.env.development | 1 + webapp/angular.json | 16 +++++++--------- webapp/src/app/app.config.ts | 3 +-- webapp/src/env.d.ts | 12 +++++------- .../src/environments/environment.development.ts | 1 - webapp/src/environments/environment.ts | 2 -- 6 files changed, 14 insertions(+), 21 deletions(-) create mode 100644 webapp/.env.development delete mode 100644 webapp/src/environments/environment.development.ts delete mode 100644 webapp/src/environments/environment.ts diff --git a/webapp/.env.development b/webapp/.env.development new file mode 100644 index 00000000..0fcf4ee6 --- /dev/null +++ b/webapp/.env.development @@ -0,0 +1 @@ +NG_APPLICATION_SERVER_URL=http://localhost:8080 diff --git a/webapp/angular.json b/webapp/angular.json index ca212e1b..368b786b 100644 --- a/webapp/angular.json +++ b/webapp/angular.json @@ -56,7 +56,11 @@ "styles": [ "src/styles.css" ], - "scripts": [] + "scripts": [], + "ngxEnv": { + "prefix": "NG_", + "root": "../../" + } }, "configurations": { "production": { @@ -77,13 +81,7 @@ "development": { "optimization": false, "extractLicenses": false, - "sourceMap": true, - "fileReplacements": [ - { - "replace": "src/environments/environment.ts", - "with": "src/environments/environment.development.ts" - } - ] + "sourceMap": true } }, "defaultConfiguration": "production" @@ -148,4 +146,4 @@ } } } -} \ No newline at end of file +} diff --git a/webapp/src/app/app.config.ts b/webapp/src/app/app.config.ts index 01a45b2d..2116172c 100644 --- a/webapp/src/app/app.config.ts +++ b/webapp/src/app/app.config.ts @@ -4,7 +4,6 @@ import { provideAnimationsAsync } from '@angular/platform-browser/animations/asy import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; import { provideAngularQuery, QueryClient } from '@tanstack/angular-query-experimental'; import { LucideAngularModule, Home, Sun, Moon, Hammer } from 'lucide-angular'; -import { APPLICATION_SERVER_URL } from 'environments/environment'; import { BASE_PATH } from 'app/core/modules/openapi'; import { routes } from 'app/app.routes'; @@ -16,6 +15,6 @@ export const appConfig: ApplicationConfig = { provideHttpClient(withInterceptorsFromDi()), provideAnimationsAsync(), importProvidersFrom(LucideAngularModule.pick({ Home, Sun, Moon, Hammer })), - { provide: BASE_PATH, useValue: APPLICATION_SERVER_URL } + { provide: BASE_PATH, useValue: import.meta.env.NG_APPLICATION_SERVER_URL } ] }; diff --git a/webapp/src/env.d.ts b/webapp/src/env.d.ts index 50d8ce3b..401d4f85 100644 --- a/webapp/src/env.d.ts +++ b/webapp/src/env.d.ts @@ -1,10 +1,8 @@ -// Define the type of the environment variables. -declare interface Env { - readonly NODE_ENV: string; - readonly APPLICATION_SERVER_URL: string; +interface ImportMeta { + readonly env: ImportMetaEnv; } -// Use import.meta.env.YOUR_ENV_VAR in your code. -declare interface ImportMeta { - readonly env: Env; +interface ImportMetaEnv { + readonly NODE_ENV: string; + readonly NG_APPLICATION_SERVER_URL: string; } diff --git a/webapp/src/environments/environment.development.ts b/webapp/src/environments/environment.development.ts deleted file mode 100644 index 64a8ea40..00000000 --- a/webapp/src/environments/environment.development.ts +++ /dev/null @@ -1 +0,0 @@ -export const APPLICATION_SERVER_URL = 'http://localhost:8080'; diff --git a/webapp/src/environments/environment.ts b/webapp/src/environments/environment.ts deleted file mode 100644 index a8619435..00000000 --- a/webapp/src/environments/environment.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const APPLICATION_SERVER_URL = import.meta.env.APPLICATION_SERVER_URL; -console.log('APPLICATION_SERVER_URL', APPLICATION_SERVER_URL);