From 9d9db315e3ec0c3126b1ed1bcfde477f855b1aed Mon Sep 17 00:00:00 2001
From: Jonas Braathen <jonas.braathen@usit.uio.no>
Date: Tue, 7 Sep 2021 23:26:38 +0200
Subject: [PATCH] Proxy requests to backend

---
 frontend/package.json |  1 +
 frontend/src/App.tsx  | 22 +++++++++++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/frontend/package.json b/frontend/package.json
index dc174c30..488d3d8b 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -24,6 +24,7 @@
     "test": "react-scripts test",
     "eject": "react-scripts eject"
   },
+  "proxy": "http://localhost:8000",
   "eslintConfig": {
     "extends": [
       "react-app",
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index de30797d..fa11d5dd 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -1,10 +1,29 @@
-import React from "react";
+import React, { useState } from "react";
 import logo from "./logo.svg";
 import "./App.css";
 
 import { appTimezone, appVersion, appTheme } from "./appConfig";
 
 const App = () => {
+  const [apiHealth, setApiHealth] = useState("not yet");
+  const [didContactApi, setDidContactApi] = useState(false);
+  if (!didContactApi) {
+    setDidContactApi(true);
+    fetch("http://localhost:3000/api/health/")
+      .then((res) => res.text())
+      .then((result) => {
+        if (result === "OK") {
+          setApiHealth("yes");
+        } else {
+          setApiHealth(result);
+        }
+      })
+      .catch((error) => {
+        setApiHealth("error");
+        console.log(error);
+      });
+  }
+
   return (
     <div className="App">
       <header className="App-header">
@@ -27,6 +46,7 @@ const App = () => {
           <br />
           Theme {appTheme}
           <br />
+          API reachable? {apiHealth}
         </p>
       </header>
     </div>
-- 
GitLab