switch in .env for dev/prod

This commit is contained in:
fred 2025-07-25 16:00:55 -07:00
parent 773b4773eb
commit a3b0fffe45
7 changed files with 29 additions and 22 deletions

View file

@ -1,23 +1,27 @@
const baseUrl = process.env.NODE_ENV === 'production'
? '/'
: 'http://localhost:3000/';
export const getRecipes = async () => {
const response = await fetch("/backend/recipes");
const response = await fetch(`${baseUrl}backend/recipes`);
const data = await response.json();
return data;
};
export const getRecipeSteps = async () => {
const response = await fetch("/backend/recipe-steps");
const response = await fetch(`${baseUrl}backend/recipe-steps`);
const data = await response.json();
return data;
};
export const getRecipeIngredients = async () => {
const response = await fetch("/backend/recipe-ingredients");
const response = await fetch(`${baseUrl}backend/recipe-ingredients`);
const data = await response.json();
return data;
};
export const getRecipeById = async (id) => {
const response = await fetch(`/backend/recipe/${id}`);
const response = await fetch(`${baseUrl}backend/recipe/${id}`);
const data = await response.json();
return data;
};
@ -25,7 +29,7 @@ export const getRecipeById = async (id) => {
export const addRecipe = async (recipeData) => {
console.log(JSON.stringify(recipeData));
// return
const response = await fetch("/backend/add-recipe", {
const response = await fetch(`${baseUrl}backend/add-recipe`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(recipeData),
@ -38,7 +42,7 @@ export const addRecipe = async (recipeData) => {
export const setDBStars = async (id, stars) => {
console.log(JSON.stringify({ id: id, stars: stars }));
// return
const response = await fetch("/backend/set-stars", {
const response = await fetch(`${baseUrl}backend/set-stars`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ id: id, stars: stars }),
@ -51,7 +55,7 @@ export const setDBStars = async (id, stars) => {
export const deleteRecipe = async (id) => {
console.log(id);
// return
const response = await fetch("/backend/delete-recipe", {
const response = await fetch(`${baseUrl}backend/delete-recipe`, {
method: "DELETE",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ id }),