From 673ac8877fcccee06473ec6cdd7207816dee7f98 Mon Sep 17 00:00:00 2001 From: MarkEhlerNV Date: Sat, 27 Jan 2024 09:25:33 -0500 Subject: [PATCH] heroku2 --- ufarms-react-client/package.json | 3 ++- ufarms-react-client/src/App.js | 7 +++++++ ufarms-react-client/static.json | 7 +++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 ufarms-react-client/static.json diff --git a/ufarms-react-client/package.json b/ufarms-react-client/package.json index a3e2b7c..9ff9a19 100644 --- a/ufarms-react-client/package.json +++ b/ufarms-react-client/package.json @@ -12,6 +12,7 @@ "web-vitals": "^2.1.4" }, "scripts": { + "heroku-postbuild": "npm install && npm run build", "start": "react-scripts start", "start-api": "cd api && venv/bin/flask run --no-debugger", "build": "react-scripts build", @@ -36,5 +37,5 @@ "last 1 safari version" ] }, - "proxy": "http://localhost:8000/" + "proxy": "https://ufarms-9d60c4fe466e.herokuapp.com/" } diff --git a/ufarms-react-client/src/App.js b/ufarms-react-client/src/App.js index c3f0a0d..426d4d1 100644 --- a/ufarms-react-client/src/App.js +++ b/ufarms-react-client/src/App.js @@ -2,9 +2,16 @@ import React, { useState, useEffect } from 'react'; import logo from './logo.svg'; import './App.css'; +// creating an env variable for local or cloud deployments would look like +// const apiUrl = process.env.NODE_ENV === 'prod' +// ? 'https://your-heroku-app-name.herokuapp.com' +// : 'http://localhost:8000'; + function App() { const [currentTime, setCurrentTime] = useState(0); +// Use apiUrl in your fetch calls +// fetch(`${apiUrl}/time`) useEffect(() => { fetch('/time').then(res => res.json()).then(data => { setCurrentTime(data.time); diff --git a/ufarms-react-client/static.json b/ufarms-react-client/static.json new file mode 100644 index 0000000..131306f --- /dev/null +++ b/ufarms-react-client/static.json @@ -0,0 +1,7 @@ +{ + "root": "build/", + "clean_urls": false, + "routes": { + "/**": "index.html" + } + } \ No newline at end of file