diff --git a/frontend/.gitignore b/frontend/.gitignore index 8a9a56a5008..720cc704bcc 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -9,7 +9,6 @@ selenium-debug.log # local env files .env.local .env.*.local -public/environment.js # Log files npm-debug.log* diff --git a/frontend/docker-setup.sh b/frontend/docker-setup.sh index 1b09235199d..e753108fb27 100755 --- a/frontend/docker-setup.sh +++ b/frontend/docker-setup.sh @@ -1,13 +1,6 @@ #!/bin/bash set -euo pipefail -BASEDIR=$(dirname "$0") -ENV_FILE=$BASEDIR"/public/environment.js" - -if [ ! -f "$ENV_FILE" ]; then - cp $BASEDIR/public/environment.docker.dist "$ENV_FILE" -fi - npm ci --verbose if [ "$CI" = 'true' ] ; then diff --git a/frontend/index.html b/frontend/index.html index f40e497c225..23f9cadfe8e 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -55,48 +55,6 @@
- diff --git a/frontend/public/environment.dist b/frontend/public/environment.dist deleted file mode 100644 index d22c43902b8..00000000000 --- a/frontend/public/environment.dist +++ /dev/null @@ -1,14 +0,0 @@ -window.environment = { - API_ROOT_URL: 'http://localhost:3001', - COOKIE_PREFIX: 'localhost_', - PRINT_URL: 'http://localhost:3003', - SENTRY_FRONTEND_DSN: null, - SENTRY_ENVIRONMENT: "http://localhost:3000", - SHARED_COOKIE_DOMAIN: 'localhost', - DEPLOYMENT_TIME: '', - VERSION: '', - VERSION_LINK_TEMPLATE: 'https://github.com/ecamp/ecamp3/commit/{version}', - TERMS_OF_SERVICE_LINK_TEMPLATE: 'https://ecamp3.ch/{lang}/tos', - FEATURE_DEVELOPER: true, - LOGIN_INFO_TEXT_KEY: 'dev' -} diff --git a/frontend/public/environment.docker.dist b/frontend/public/environment.docker.dist deleted file mode 100644 index d22c43902b8..00000000000 --- a/frontend/public/environment.docker.dist +++ /dev/null @@ -1,14 +0,0 @@ -window.environment = { - API_ROOT_URL: 'http://localhost:3001', - COOKIE_PREFIX: 'localhost_', - PRINT_URL: 'http://localhost:3003', - SENTRY_FRONTEND_DSN: null, - SENTRY_ENVIRONMENT: "http://localhost:3000", - SHARED_COOKIE_DOMAIN: 'localhost', - DEPLOYMENT_TIME: '', - VERSION: '', - VERSION_LINK_TEMPLATE: 'https://github.com/ecamp/ecamp3/commit/{version}', - TERMS_OF_SERVICE_LINK_TEMPLATE: 'https://ecamp3.ch/{lang}/tos', - FEATURE_DEVELOPER: true, - LOGIN_INFO_TEXT_KEY: 'dev' -} diff --git a/frontend/public/environment.js b/frontend/public/environment.js new file mode 100644 index 00000000000..47b91ee3e64 --- /dev/null +++ b/frontend/public/environment.js @@ -0,0 +1,5 @@ +/** + * This is a placeholder. + * In production, this file is filled with the values for window.environment. + * In development, window.environment is filled in src/dev-environment.js + */ diff --git a/frontend/src/dev-environment.js b/frontend/src/dev-environment.js new file mode 100644 index 00000000000..431f60c82ba --- /dev/null +++ b/frontend/src/dev-environment.js @@ -0,0 +1,21 @@ +// you can overwrite the env variables locally in frontend/env.local +// @see https://vitejs.dev/guide/env-and-mode.html +if (!window.environment) { + const env = import.meta.env + window.environment = { + API_ROOT_URL: env.VITE_API_ROOT_URL ?? 'http://localhost:3001', + COOKIE_PREFIX: env.VITE_COOKIE_PREFIX ?? 'localhost_', + PRINT_URL: env.VITE_PRINT_URL ?? 'http://localhost:3003', + SENTRY_FRONTEND_DSN: env.VITE_SENTRY_FRONTEND_DSN, + SENTRY_ENVIRONMENT: env.VITE_SENTRY_ENVIRONMENT ?? 'http://localhost:3000', + SHARED_COOKIE_DOMAIN: env.VITE_SHARED_COOKIE_DOMAIN ?? 'localhost', + DEPLOYMENT_TIME: env.VITE_DEPLOYMENT_TIME ?? '', + VERSION: env.VITE_VERSION ?? '', + VERSION_LINK_TEMPLATE: + env.VITE_VERSION_LINK_TEMPLATE ?? + 'https://github.com/ecamp/ecamp3/commit/{version}', + FEATURE_DEVELOPER: env.VITE_FEATURE_DEVELOPER ?? true, + LOGIN_INFO_TEXT_KEY: env.VITE_LOGIN_INFO_TEXT_KEY ?? 'dev', + } +} +export const getEnv = () => window.environment diff --git a/frontend/src/main.js b/frontend/src/main.js index f3be61c1888..b163f86c2fa 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -1,3 +1,5 @@ +//getEnv needs to be imported first +import { getEnv } from '@/dev-environment' import Vue from 'vue' import App from './App.vue' import router from '@/router.js' @@ -20,6 +22,8 @@ import 'vue-toastification/dist/index.css' import { Resize } from 'vuetify/lib/directives' +getEnv() + if (window.environment && window.environment.SENTRY_FRONTEND_DSN) { const environment = window.environment.SENTRY_ENVIRONMENT ?? 'http://localhost:3000' Sentry.init({