diff --git a/frontend/.env.example b/frontend/.env.example new file mode 100644 index 0000000..5317fce --- /dev/null +++ b/frontend/.env.example @@ -0,0 +1 @@ +VITE_API_URL=http://localhost:3000 diff --git a/frontend/src/services/api.ts b/frontend/src/services/api.ts index d97db38..55f4791 100644 --- a/frontend/src/services/api.ts +++ b/frontend/src/services/api.ts @@ -4,7 +4,11 @@ import type { EncryptedNote, LoginCredentials, RegisterCredentials, User } from '../models/types'; -const API_BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:3000'; +const API_BASE_URL = import.meta.env.VITE_API_URL; + +if (!API_BASE_URL) { + throw new Error('VITE_API_URL environment variable is not defined'); +} class ApiClient { private baseUrl: string; diff --git a/frontend/src/test/setup.ts b/frontend/src/test/setup.ts index 28dc603..7dcd43c 100644 --- a/frontend/src/test/setup.ts +++ b/frontend/src/test/setup.ts @@ -2,7 +2,10 @@ * Test setup file for Vitest */ -import { expect, afterEach } from 'vitest'; +import { afterEach, vi } from 'vitest'; + +// Mock environment variables +vi.stubEnv('VITE_API_URL', 'http://localhost:3000'); import { cleanup } from '@testing-library/react'; import '@testing-library/jest-dom';