From f08bd430f3af60bde5d1c0891b8cd2af9117e58a Mon Sep 17 00:00:00 2001 From: Sindre Kjelsrud Date: Thu, 2 May 2024 16:31:34 +0200 Subject: [PATCH] :technologist: add environment variable for url in frontend Signed-off-by: Sindre Kjelsrud --- frontend/.env.example | 2 ++ frontend/src/api/getUserQuestions.ts | 4 +++- frontend/src/api/postBugData.ts | 4 +++- frontend/src/api/postEvaluationData.ts | 4 +++- frontend/src/api/postFormData.ts | 4 +++- frontend/src/api/postUserformData.ts | 4 +++- frontend/svelte.config.js | 2 +- 7 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 frontend/.env.example diff --git a/frontend/.env.example b/frontend/.env.example new file mode 100644 index 0000000..22a8ff5 --- /dev/null +++ b/frontend/.env.example @@ -0,0 +1,2 @@ +# URL variable +VITE_URL="http://localhost:8080" \ No newline at end of file diff --git a/frontend/src/api/getUserQuestions.ts b/frontend/src/api/getUserQuestions.ts index 359905b..a80f23f 100644 --- a/frontend/src/api/getUserQuestions.ts +++ b/frontend/src/api/getUserQuestions.ts @@ -1,3 +1,5 @@ +const URL = import.meta.env.VITE_URL; + interface Question { QuestionID: number; QuestionText: string; @@ -22,7 +24,7 @@ interface QAData { export const getUserQuestions = async ( respondentID: number ): Promise => { - let url = `https://helseundersokelsen.online/userquestions?respondentID=${respondentID}`; + let url = `${URL}/userquestions?respondentID=${respondentID}`; const response = fetch(url, { method: "GET", diff --git a/frontend/src/api/postBugData.ts b/frontend/src/api/postBugData.ts index 07fa330..80c0903 100644 --- a/frontend/src/api/postBugData.ts +++ b/frontend/src/api/postBugData.ts @@ -1,5 +1,7 @@ +const URL = import.meta.env.VITE_URL; + export const postBugData = async (bugText: string) => { - let url = "https://helseundersokelsen.online/submitbug"; + let url = `${URL}/submitbug`; const response = fetch(url, { method: "POST", diff --git a/frontend/src/api/postEvaluationData.ts b/frontend/src/api/postEvaluationData.ts index 2ede934..781d95f 100644 --- a/frontend/src/api/postEvaluationData.ts +++ b/frontend/src/api/postEvaluationData.ts @@ -1,5 +1,7 @@ +const URL = import.meta.env.VITE_URL; + export const postEvaluationData = async (evaluationText: string) => { - let url = "https://helseundersokelsen.online/submiteval"; + let url = `${URL}/submiteval`; const response = fetch(url, { method: "POST", diff --git a/frontend/src/api/postFormData.ts b/frontend/src/api/postFormData.ts index 64fc140..2c15d82 100644 --- a/frontend/src/api/postFormData.ts +++ b/frontend/src/api/postFormData.ts @@ -1,8 +1,10 @@ +const URL = import.meta.env.VITE_URL; + export const postFormData = async ( respondentID: number, allFormAnswers: string ) => { - let url = "https://helseundersokelsen.online/submitanswers"; + let url = `${URL}/submitanswers`; const response = fetch(url, { method: "POST", diff --git a/frontend/src/api/postUserformData.ts b/frontend/src/api/postUserformData.ts index bcfa05b..168c2d6 100644 --- a/frontend/src/api/postUserformData.ts +++ b/frontend/src/api/postUserformData.ts @@ -1,3 +1,5 @@ +const URL = import.meta.env.VITE_URL; + interface postUserformDataReponse { respondentID: number; } @@ -12,7 +14,7 @@ export const postUserformData = async ( county: string, submit_date: string ): Promise => { - let url = "https://helseundersokelsen.online/submituserform"; + let url = `${URL}/submituserform`; let personnel = healthcare_personnel == "Ja" ? true : false; let licensed = is_licensed == "Ja" ? true : false; let answered_before = has_answered_before == "Ja" ? true : false; diff --git a/frontend/svelte.config.js b/frontend/svelte.config.js index fe05d1f..3eba69c 100644 --- a/frontend/svelte.config.js +++ b/frontend/svelte.config.js @@ -1,4 +1,4 @@ -import adapter from "@sveltejs/adapter-vercel"; +import adapter from "@sveltejs/adapter-auto"; import { vitePreprocess } from "@sveltejs/vite-plugin-svelte"; /** @type {import('@sveltejs/kit').Config} */