Skip to content

Commit

Permalink
Moved API_URL to env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
pkirilin committed Nov 8, 2023
1 parent cecdc85 commit 0b3b89d
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/frontend/.env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
VITE_APP_MSW_ENABLED=false
VITE_APP_API_URL=https://localhost:5001
1 change: 1 addition & 0 deletions src/frontend/.env.production
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
VITE_APP_MSW_ENABLED=false
VITE_APP_API_URL=https://food-diary.azurewebsites.net
4 changes: 1 addition & 3 deletions src/frontend/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
7 changes: 0 additions & 7 deletions src/frontend/src/features/__shared__/config.ts

This file was deleted.

10 changes: 5 additions & 5 deletions src/frontend/src/features/notes/thunks.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -26,14 +26,14 @@ export interface DeleteNotePayload extends NoteOperationPayload {

export const getNotes = createApiCallAsyncThunk<NoteItem[], GetNotesRequest>(
'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<void, CreateNotePayload>(
'notes/createNote',
() => `${config.apiUrl}/api/v1/notes`,
() => `${API_URL}/api/v1/notes`,
handleEmptyResponse,
'Failed to create note',
{
Expand All @@ -44,7 +44,7 @@ export const createNote = createApiCallAsyncThunk<void, CreateNotePayload>(

export const editNote = createApiCallAsyncThunk<void, EditNotePayload>(
'notes/editNote',
({ id }) => `${config.apiUrl}/api/v1/notes/${id}`,
({ id }) => `${API_URL}/api/v1/notes/${id}`,
handleEmptyResponse,
'Failed to update note',
{
Expand All @@ -55,7 +55,7 @@ export const editNote = createApiCallAsyncThunk<void, EditNotePayload>(

export const deleteNote = createApiCallAsyncThunk<void, DeleteNotePayload>(
'notes/deleteNote',
({ id }) => `${config.apiUrl}/api/v1/notes/${id}`,
({ id }) => `${API_URL}/api/v1/notes/${id}`,
handleEmptyResponse,
'Failed to delete note',
{
Expand Down
18 changes: 9 additions & 9 deletions src/frontend/src/features/pages/thunks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import config from '../__shared__/config';
import { API_URL } from 'src/config';
import { SortOrder } from '../__shared__/models';
import {
createApiCallAsyncThunk,
Expand Down Expand Up @@ -27,21 +27,21 @@ export interface PageByIdResponse {

export const getPages = createApiCallAsyncThunk<PagesSearchResult, GetPagesRequest>(
'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<PageByIdResponse, number>(
'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<number, PageCreateEdit>(
'pages/createPage',
() => `${config.apiUrl}/api/v1/pages`,
() => `${API_URL}/api/v1/pages`,
async response => Number(await response.text()),
'Failed to create page',
{
Expand All @@ -52,7 +52,7 @@ export const createPage = createApiCallAsyncThunk<number, PageCreateEdit>(

export const editPage = createApiCallAsyncThunk<void, EditPageRequest>(
'pages/editPage',
({ id }) => `${config.apiUrl}/api/v1/pages/${id}`,
({ id }) => `${API_URL}/api/v1/pages/${id}`,
handleEmptyResponse,
'Failed to update page',
{
Expand All @@ -63,7 +63,7 @@ export const editPage = createApiCallAsyncThunk<void, EditPageRequest>(

export const deletePages = createApiCallAsyncThunk<void, number[]>(
'pages/deletePages',
() => `${config.apiUrl}/api/v1/pages/batch`,
() => `${API_URL}/api/v1/pages/batch`,
handleEmptyResponse,
'Failed to delete pages',
{
Expand All @@ -74,7 +74,7 @@ export const deletePages = createApiCallAsyncThunk<void, number[]>(

export const exportPagesToJson = createApiCallAsyncThunk<void, ExportPagesToJsonRequest>(
'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`);
Expand All @@ -84,7 +84,7 @@ export const exportPagesToJson = createApiCallAsyncThunk<void, ExportPagesToJson

export const importPages = createApiCallAsyncThunk<void, File>(
'pages/importPages',
() => `${config.apiUrl}/api/v1/imports/json`,
() => `${API_URL}/api/v1/imports/json`,
handleEmptyResponse,
'Failed to import pages',
{
Expand All @@ -100,7 +100,7 @@ export const importPages = createApiCallAsyncThunk<void, File>(

export const getDateForNewPage = createApiCallAsyncThunk<string, void>(
'pages/getDateForNewPage',
() => `${config.apiUrl}/api/v1/pages/date`,
() => `${API_URL}/api/v1/pages/date`,
response => response.text(),
'Failed to get date for new page',
);
1 change: 1 addition & 0 deletions src/frontend/src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 0b3b89d

Please sign in to comment.