From 1345cfbe6557f79c084b236f3dcc1286a6423a68 Mon Sep 17 00:00:00 2001 From: Bruno Tot Date: Thu, 29 Aug 2024 16:42:15 +0200 Subject: [PATCH] chore: fix invalid env variables load in vite config --- .vscode/launch.json | 8 ++++---- packages/frontend/src/setup/apiClient.setup.ts | 10 +++++++++- packages/frontend/vite.config.ts | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 49187d13..8227b721 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -138,26 +138,26 @@ }, { "name": "backend > build", - "runtimeArgs": ["run", "--filter", "backend", "build"], + "runtimeArgs": ["run", "build", "--prefix", "packages/backend"], "presentation": { "group": "3" }, // Defaults below "runtimeVersion": "21.7.0", "type": "node", "request": "launch", - "runtimeExecutable": "pnpm", + "runtimeExecutable": "npm", "console": "integratedTerminal", "outputCapture": "std", "autoAttachChildProcesses": false }, { "name": "frontend > dev", - "runtimeArgs": ["run", "--filter", "frontend", "dev"], + "runtimeArgs": ["run", "dev", "--prefix", "packages/frontend"], "presentation": { "group": "4" }, // Defaults below "runtimeVersion": "21.7.0", "type": "node", "request": "launch", - "runtimeExecutable": "pnpm", + "runtimeExecutable": "npm", "console": "integratedTerminal", "outputCapture": "std", "autoAttachChildProcesses": false diff --git a/packages/frontend/src/setup/apiClient.setup.ts b/packages/frontend/src/setup/apiClient.setup.ts index 646ff9f4..b80538f8 100644 --- a/packages/frontend/src/setup/apiClient.setup.ts +++ b/packages/frontend/src/setup/apiClient.setup.ts @@ -1,7 +1,15 @@ import { initClient } from "@ts-rest/core"; import { contracts } from "@org/shared"; +console.log(import.meta.env); + +const API_CLIENT_URL = import.meta.env.VITE_API_CLIENT_URL; + +if (!API_CLIENT_URL) { + throw new Error("Env variable: 'API_CLIENT_URL' is not defined"); +} + export const apiClient = initClient(contracts, { - baseUrl: import.meta.env.VITE_API_CLIENT_URL, + baseUrl: API_CLIENT_URL, baseHeaders: {}, }); diff --git a/packages/frontend/vite.config.ts b/packages/frontend/vite.config.ts index c8cf23a0..88150a0e 100644 --- a/packages/frontend/vite.config.ts +++ b/packages/frontend/vite.config.ts @@ -4,6 +4,7 @@ import { defineConfig } from "vite"; // https://vitejs.dev/config/ export default defineConfig({ + envDir: path.resolve(__dirname), root: path.resolve(__dirname, "src"), build: { outDir: path.resolve(__dirname, "dist"),