From 2449294066727ea0a494bdcce128e025a4728d41 Mon Sep 17 00:00:00 2001 From: Henrik Steen Date: Thu, 18 Jul 2024 06:19:41 +0200 Subject: [PATCH] Migrate override of BACKEND_URL --- README.md | 23 ++++++++++++----------- frontend/src/api.ts | 5 +---- frontend/vite.config.ts | 18 ------------------ 3 files changed, 13 insertions(+), 33 deletions(-) delete mode 100644 frontend/vite.config.ts diff --git a/README.md b/README.md index f3f08c65..77c9012f 100644 --- a/README.md +++ b/README.md @@ -89,33 +89,34 @@ For å gjøre lokal utvikling trenger du: ### Kjøre frontend lokalt -Frontend kan utvikles direkte mot backend i produksjon. Tilpass `BACKEND_URL` -etter hva du ønsker å gå mot. - 1. ```bash cd frontend ``` -1. Installer/oppdater avhengigheter: +2. Installer/oppdater avhengigheter: ```bash npm ci ``` -1. Kjør lokal server - - enten mot lokalt: +3. Kjør lokal server ```bash - BACKEND_URL=http://localhost:8081/ npx ng servce --port 3000 --open + npx ng serve --port 3000 --open ``` - eller mot produksjon: + Denne går mot lokal backend som standard. + For å gå mot produksjon kan man kjøre følgende i nettleser-konsollen (og oppdater siden): - ```bash - BACKEND_URL=https://billett.blindernuka.no/ npx ng servce --port 3000 --open + ```js + localStorage.setItem("billett-baseurl", "https://billett.blindernuka.no/") ``` + Og for å endre tilbake: + + ```js + localStorage.removeItem("billett-baseurl") + ### phpMyAdmin Kan brukes for å enkelt se og gjøre manuelle endringer i den lokale databasen. diff --git a/frontend/src/api.ts b/frontend/src/api.ts index 188a4cdc..f0fc6066 100644 --- a/frontend/src/api.ts +++ b/frontend/src/api.ts @@ -1,7 +1,4 @@ -// TODO(migrate): Support BACKEND_URL env override. -const BACKEND_URL = "/" - -export let backendUrl = BACKEND_URL +export let backendUrl = localStorage.getItem("billett-baseurl") ?? "/" if (backendUrl.includes("SAMEHOST")) { backendUrl = backendUrl.replace("SAMEHOST", window.location.hostname) diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts deleted file mode 100644 index a8448ecd..00000000 --- a/frontend/vite.config.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { defineConfig } from "vite" -import babel from "vite-plugin-babel" - -export default defineConfig({ - plugins: [ - babel({ - babelConfig: { - babelrc: false, - configFile: false, - plugins: ["angularjs-annotate"], - }, - }), - ], - define: { - DEBUG: !!process.env.DEBUG ?? false, - BACKEND_URL: JSON.stringify(process.env.BACKEND_URL ?? "/"), - }, -})