From 5f1b0bb1883a8021c7261dad59e063824849fd81 Mon Sep 17 00:00:00 2001 From: realtradam Date: Wed, 22 May 2024 19:05:07 -0400 Subject: add prod/dev env vars --- .env.development | 2 ++ .env.production | 2 ++ index.html | 2 +- src/App.jsx | 7 +++++++ src/App.tsx | 7 ------- src/components/Blogs.jsx | 2 +- src/components/Game.jsx | 4 ++-- src/components/GameCard.jsx | 6 +++--- src/components/Games.jsx | 6 +++--- src/components/Home.jsx | 6 +++--- src/components/Layout.jsx | 11 ----------- src/main.jsx | 12 ++++++++++++ src/main.tsx | 10 ---------- src/routes/index.jsx | 2 +- 14 files changed, 37 insertions(+), 42 deletions(-) create mode 100644 .env.development create mode 100644 .env.production create mode 100644 src/App.jsx delete mode 100644 src/App.tsx create mode 100644 src/main.jsx delete mode 100644 src/main.tsx diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..93b132e --- /dev/null +++ b/.env.development @@ -0,0 +1,2 @@ +# .env.development +VITE_API_TITLE=http://localhost:3000 diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..175ef0a --- /dev/null +++ b/.env.production @@ -0,0 +1,2 @@ +# .env.production +VITE_API_TITLE=https://gameshost.tradam.dev diff --git a/index.html b/index.html index dcb63bf..34f3cd9 100644 --- a/index.html +++ b/index.html @@ -29,6 +29,6 @@
- + diff --git a/src/App.jsx b/src/App.jsx new file mode 100644 index 0000000..b594288 --- /dev/null +++ b/src/App.jsx @@ -0,0 +1,7 @@ +import React from "react"; +import Routes from "./routes"; + +export default (props) => { + return (); +} + diff --git a/src/App.tsx b/src/App.tsx deleted file mode 100644 index b594288..0000000 --- a/src/App.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from "react"; -import Routes from "./routes"; - -export default (props) => { - return (); -} - diff --git a/src/components/Blogs.jsx b/src/components/Blogs.jsx index f52f286..2dc8f27 100644 --- a/src/components/Blogs.jsx +++ b/src/components/Blogs.jsx @@ -6,7 +6,7 @@ const Blogs = () => { const [blogs, setBlogs] = useState([]); useEffect(() => { - const url = "/api/v1/blogs/index"; + const url = `${import.meta.env.VITE_API_TITLE}/api/v1/blogs/index`; fetch(url).then((response) => { if (response.ok) { return response.json(); diff --git a/src/components/Game.jsx b/src/components/Game.jsx index 8b80b8e..7746767 100644 --- a/src/components/Game.jsx +++ b/src/components/Game.jsx @@ -9,13 +9,13 @@ import Button from "./Button"; //export default () => ( export default function Games () { let { user, game } = useParams(); -//http://localhost:3000/api/v1/game/realtradam/orc-arena-of-time/index.html +//http://%{VITE_API_TITLE}/api/v1/game/realtradam/orc-arena-of-time/index.html return( <>
Orc: Arena of Time
- +
diff --git a/src/components/GameCard.jsx b/src/components/GameCard.jsx index 9cd815d..82ad423 100644 --- a/src/components/GameCard.jsx +++ b/src/components/GameCard.jsx @@ -15,10 +15,10 @@ export default function GameCard ({ link = "./", width = "72", game = { card_img
- +
- - + +
diff --git a/src/components/Games.jsx b/src/components/Games.jsx index f1545b8..a0646be 100644 --- a/src/components/Games.jsx +++ b/src/components/Games.jsx @@ -7,13 +7,13 @@ import Button from "./Button"; export default function Games () { const [games, setGames] = useState([]); useEffect(() => { - const url = "/api/v1/games"; + const url = `${import.meta.env.VITE_API_TITLE}/api/v1/games`; fetch(url).then((response) => { if (response.ok) { return response.json(); } throw new Error("Network response was not ok."); - }).then((response) => setGames(response)).catch(() => navigate("/")); + }).then((response) => setGames(response))//.catch(() => navigate("/")); }, []); const allGames = games.map((game) => ( @@ -35,7 +35,7 @@ export default function Games () { console.log(pair[0] + ', ' + pair[1]) }; - fetch('http://127.0.0.1:3000/api/v1/games', { + fetch('${import.meta.env.VITE_API_TITLE}/api/v1/games', { method: 'post', body: formData, }); diff --git a/src/components/Home.jsx b/src/components/Home.jsx index 863d81d..c1fb689 100644 --- a/src/components/Home.jsx +++ b/src/components/Home.jsx @@ -15,7 +15,7 @@ export default function Home () { console.log(pair[0] + ', ' + pair[1]) }; - fetch('http://127.0.0.1:3000/api/v1/games', { + fetch('${import.meta.env.VITE_API_TITLE}/api/v1/games', { method: 'post', body: formData, }); @@ -24,11 +24,11 @@ export default function Home () { <>
-
Get To Know Me a Little
+
Work In Progress
-

Debug! Again

+

API at: { import.meta.env.VITE_API_TITLE }

Ea optio vitae culpa voluptatem consectetur. Ab quisquam sed ipsum. Perspiciatis minus odit quas qui consequuntur dicta reiciendis a. Nihil minima sed aliquam.

diff --git a/src/components/Layout.jsx b/src/components/Layout.jsx index 9aac935..06df03a 100644 --- a/src/components/Layout.jsx +++ b/src/components/Layout.jsx @@ -6,17 +6,6 @@ export default function Layout ({userData}) console.log(userData); //const [userData, setUserData] = useState({ name: "" }); - // if the user tries to access the isolated domain then we redirect them - // this is NOT done for security, only for good UX - // rails serves the react app no matter what - // so the app would be broken when served on the isolated domain - const domain = window.location.host; - console.log(domain); - //if(domain === "localhost:3000") - //{ - // window.location.replace("http://127.0.0.1:3000"); - //} - return ( <>
diff --git a/src/main.jsx b/src/main.jsx new file mode 100644 index 0000000..ac292fd --- /dev/null +++ b/src/main.jsx @@ -0,0 +1,12 @@ +import React from 'react' +import ReactDOM from 'react-dom/client' +import App from './App.jsx' +import './index.css' + + // null assertion for tsx +//ReactDOM.createRoot(document.getElementById('root')!).render( +ReactDOM.createRoot(document.getElementById('root')).render( + + + , +) diff --git a/src/main.tsx b/src/main.tsx deleted file mode 100644 index 3d7150d..0000000 --- a/src/main.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import React from 'react' -import ReactDOM from 'react-dom/client' -import App from './App.tsx' -import './index.css' - -ReactDOM.createRoot(document.getElementById('root')!).render( - - - , -) diff --git a/src/routes/index.jsx b/src/routes/index.jsx index df46102..5809fbb 100644 --- a/src/routes/index.jsx +++ b/src/routes/index.jsx @@ -9,7 +9,7 @@ import Layout from "../components/Layout"; export default function index() { const [userData, setUserData] = useState({}); - const url = "http://localhost:3000/api/v1/auth/data"; + const url = `${import.meta.env.VITE_API_TITLE}/api/v1/auth/data`; useEffect(() => { fetch(url, { credentials: "include" -- cgit v1.2.3