diff --git a/src/frontend/.env b/src/frontend/.env index ed0b7b6fd..52c7fd830 100644 --- a/src/frontend/.env +++ b/src/frontend/.env @@ -1 +1,2 @@ VITE_APP_MSW_ENABLED=false +VITE_APP_API_URL=https://localhost:5001 diff --git a/src/frontend/.env.production b/src/frontend/.env.production index ed0b7b6fd..309e3bf12 100644 --- a/src/frontend/.env.production +++ b/src/frontend/.env.production @@ -1 +1,2 @@ VITE_APP_MSW_ENABLED=false +VITE_APP_API_URL=https://food-diary.azurewebsites.net diff --git a/src/frontend/src/config/index.ts b/src/frontend/src/config/index.ts index 9a1d104ee..68b854941 100644 --- a/src/frontend/src/config/index.ts +++ b/src/frontend/src/config/index.ts @@ -1,6 +1,4 @@ -import config from '../features/__shared__/config'; - -export const { apiUrl: API_URL } = config; +export const API_URL = import.meta.env.VITE_APP_API_URL; export const AUTH_CHECK_INTERVAL = import.meta.env.VITE_APP_AUTH_CHECK_INTERVAL ? Number(import.meta.env.VITE_APP_AUTH_CHECK_INTERVAL) diff --git a/src/frontend/src/features/__shared__/config.ts b/src/frontend/src/features/__shared__/config.ts deleted file mode 100644 index b489dd1fb..000000000 --- a/src/frontend/src/features/__shared__/config.ts +++ /dev/null @@ -1,7 +0,0 @@ -const apiUrl = import.meta.env.PROD - ? 'https://food-diary.azurewebsites.net' - : 'https://localhost:5001'; - -export default { - apiUrl, -}; diff --git a/src/frontend/src/features/notes/thunks.ts b/src/frontend/src/features/notes/thunks.ts index d0f5f2fb4..4ee1ab887 100644 --- a/src/frontend/src/features/notes/thunks.ts +++ b/src/frontend/src/features/notes/thunks.ts @@ -1,4 +1,4 @@ -import config from '../__shared__/config'; +import { API_URL } from 'src/config'; import { createApiCallAsyncThunk, createUrl, handleEmptyResponse } from '../__shared__/utils'; import { MealType, NoteCreateEdit, NoteItem } from './models'; @@ -26,14 +26,14 @@ export interface DeleteNotePayload extends NoteOperationPayload { export const getNotes = createApiCallAsyncThunk( 'notes/getNotes', - params => createUrl(`${config.apiUrl}/api/v1/notes`, params), + params => createUrl(`${API_URL}/api/v1/notes`, params), response => response.json(), 'Failed to get notes', ); export const createNote = createApiCallAsyncThunk( 'notes/createNote', - () => `${config.apiUrl}/api/v1/notes`, + () => `${API_URL}/api/v1/notes`, handleEmptyResponse, 'Failed to create note', { @@ -44,7 +44,7 @@ export const createNote = createApiCallAsyncThunk( export const editNote = createApiCallAsyncThunk( 'notes/editNote', - ({ id }) => `${config.apiUrl}/api/v1/notes/${id}`, + ({ id }) => `${API_URL}/api/v1/notes/${id}`, handleEmptyResponse, 'Failed to update note', { @@ -55,7 +55,7 @@ export const editNote = createApiCallAsyncThunk( export const deleteNote = createApiCallAsyncThunk( 'notes/deleteNote', - ({ id }) => `${config.apiUrl}/api/v1/notes/${id}`, + ({ id }) => `${API_URL}/api/v1/notes/${id}`, handleEmptyResponse, 'Failed to delete note', { diff --git a/src/frontend/src/features/pages/thunks.ts b/src/frontend/src/features/pages/thunks.ts index 18bbe0d24..3d5e386a7 100644 --- a/src/frontend/src/features/pages/thunks.ts +++ b/src/frontend/src/features/pages/thunks.ts @@ -1,4 +1,4 @@ -import config from '../__shared__/config'; +import { API_URL } from 'src/config'; import { SortOrder } from '../__shared__/models'; import { createApiCallAsyncThunk, @@ -27,21 +27,21 @@ export interface PageByIdResponse { export const getPages = createApiCallAsyncThunk( 'pages/getPages', - params => createUrl(`${config.apiUrl}/api/v1/pages`, params), + params => createUrl(`${API_URL}/api/v1/pages`, params), response => response.json(), 'Failed to get pages', ); export const getPageById = createApiCallAsyncThunk( 'pages/getPageById', - id => `${config.apiUrl}/api/v1/pages/${id}`, + id => `${API_URL}/api/v1/pages/${id}`, response => response.json(), 'Failed to get page', ); export const createPage = createApiCallAsyncThunk( 'pages/createPage', - () => `${config.apiUrl}/api/v1/pages`, + () => `${API_URL}/api/v1/pages`, async response => Number(await response.text()), 'Failed to create page', { @@ -52,7 +52,7 @@ export const createPage = createApiCallAsyncThunk( export const editPage = createApiCallAsyncThunk( 'pages/editPage', - ({ id }) => `${config.apiUrl}/api/v1/pages/${id}`, + ({ id }) => `${API_URL}/api/v1/pages/${id}`, handleEmptyResponse, 'Failed to update page', { @@ -63,7 +63,7 @@ export const editPage = createApiCallAsyncThunk( export const deletePages = createApiCallAsyncThunk( 'pages/deletePages', - () => `${config.apiUrl}/api/v1/pages/batch`, + () => `${API_URL}/api/v1/pages/batch`, handleEmptyResponse, 'Failed to delete pages', { @@ -74,7 +74,7 @@ export const deletePages = createApiCallAsyncThunk( export const exportPagesToJson = createApiCallAsyncThunk( 'pages/exportToJson', - params => createUrl(`${config.apiUrl}/api/v1/exports/json`, { ...params }), + params => createUrl(`${API_URL}/api/v1/exports/json`, { ...params }), async (response, { startDate, endDate }) => { const blob = await response.blob(); downloadFile(blob, `FoodDiary_${startDate}_${endDate}.json`); @@ -84,7 +84,7 @@ export const exportPagesToJson = createApiCallAsyncThunk( 'pages/importPages', - () => `${config.apiUrl}/api/v1/imports/json`, + () => `${API_URL}/api/v1/imports/json`, handleEmptyResponse, 'Failed to import pages', { @@ -100,7 +100,7 @@ export const importPages = createApiCallAsyncThunk( export const getDateForNewPage = createApiCallAsyncThunk( 'pages/getDateForNewPage', - () => `${config.apiUrl}/api/v1/pages/date`, + () => `${API_URL}/api/v1/pages/date`, response => response.text(), 'Failed to get date for new page', ); diff --git a/src/frontend/src/vite-env.d.ts b/src/frontend/src/vite-env.d.ts index 51940a007..7c1fc2b1c 100644 --- a/src/frontend/src/vite-env.d.ts +++ b/src/frontend/src/vite-env.d.ts @@ -8,4 +8,5 @@ interface ImportMetaEnv { readonly VITE_APP_MSW_ENABLED: string; readonly VITE_APP_AUTH_CHECK_INTERVAL: string; readonly VITE_APP_DEMO_MODE_ENABLED: string; + readonly VITE_APP_API_URL: string; }