From d40d03fbc202550fd11df08bf4f54cb656657bf1 Mon Sep 17 00:00:00 2001
From: rlacko <rlacko@sch.bme.hu>
Date: Thu, 27 Aug 2020 21:53:46 +0200
Subject: [PATCH] add caddy local proxy setup

---
 .prettierignore                     |  4 +-
 README.md                           | 42 ++++--------------
 package-lock.json                   | 66 +----------------------------
 package.json                        |  1 -
 src/core/components/ContextTest.tsx |  1 +
 src/setupProxy.js                   | 11 -----
 tools/local_proxy/Caddyfile         | 13 ++++++
 7 files changed, 26 insertions(+), 112 deletions(-)
 delete mode 100644 src/setupProxy.js
 create mode 100644 tools/local_proxy/Caddyfile

diff --git a/.prettierignore b/.prettierignore
index 18a79da..af62006 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -62,4 +62,6 @@ config/*
 
 # Auto generated by React
 serviceWorker.*
-setupTests.*
\ No newline at end of file
+setupTests.*
+
+tools/*
\ No newline at end of file
diff --git a/README.md b/README.md
index 5f6fa93..b3d603f 100644
--- a/README.md
+++ b/README.md
@@ -1,37 +1,11 @@
-This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
-
-Environment variables needed in development found in `.env.example` !
-
-## Available Scripts
-
-In the project directory, you can run:
-
-### `npm start`
-
-Runs the app in the development mode.<br />
-Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
-
-### `npm test`
-
-Launches the test runner in the interactive watch mode.<br />
-See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
+## BodySCH Frontend
 
-### `npm run build`
-
-Builds the app
-
-### `npm run lint`
-
-Runs the linter in the console.
-
-### `npm run format`
-
-Format the files in the project with prettier.
-
-### `npm run validate`
-
-Checks the formatting and linter rules for all the files in the source.
+This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
 
-### `npm run fix`
+#### Local proxy
 
-It runs the formatting and the linter with --fix option
+`./tools/local_proxy/Caddyfile/`  
+Create a local proxy with caddy:  
+`docker run -d -it --name caddyFrontend -v /path/to/Caddyfile:/etc/caddy/Caddyfile --network host caddy`  
+When you change the config just `docker stop ...` and `docker start ...`.  
+If you experience any error check it with `docker logs ...`.
diff --git a/package-lock.json b/package-lock.json
index fa80be4..927b173 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -2934,20 +2934,11 @@
       "version": "3.3.1",
       "resolved": "https://registry.npmjs.org/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz",
       "integrity": "sha512-iMIqiko6ooLrTh1joXodJK5X9xeEALT1kM5G3ZLhD3hszxBdIEd5C75U834D9mLcINgD4OyZf5uQXjkuYydWvA==",
-      "dev": true,
       "requires": {
         "@types/react": "*",
         "hoist-non-react-statics": "^3.3.0"
       }
     },
-    "@types/http-proxy": {
-      "version": "1.17.4",
-      "resolved": "https://registry.npmjs.org/@types/http-proxy/-/http-proxy-1.17.4.tgz",
-      "integrity": "sha512-IrSHl2u6AWXduUaDLqYpt45tLVCtYv7o4Z0s1KghBCDgIIS9oW5K1H8mZG/A2CfeLdEa7rTd1ACOiHBc1EMT2Q==",
-      "requires": {
-        "@types/node": "*"
-      }
-    },
     "@types/istanbul-lib-coverage": {
       "version": "2.0.1",
       "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.1.tgz",
@@ -3037,7 +3028,6 @@
       "version": "0.63.6",
       "resolved": "https://registry.npmjs.org/@types/react-native/-/react-native-0.63.6.tgz",
       "integrity": "sha512-qAv/VOyXAk4it9MOsQoyUjUnEJ3kAW1FCRGi0OvfQDKLH1/FFogVFvoB6xAlBNc6lPyBtCg+nvzj/ScYe0PqCQ==",
-      "dev": true,
       "requires": {
         "@types/react": "*"
       }
@@ -3080,7 +3070,6 @@
       "version": "5.1.2",
       "resolved": "https://registry.npmjs.org/@types/styled-components/-/styled-components-5.1.2.tgz",
       "integrity": "sha512-HNocYLfrsnNNm8NTS/W53OERSjRA8dx5Bn6wBd2rXXwt4Z3s+oqvY6/PbVt3e6sgtzI63GX//WiWiRhWur08qQ==",
-      "dev": true,
       "requires": {
         "@types/hoist-non-react-statics": "*",
         "@types/react": "*",
@@ -3091,8 +3080,7 @@
         "csstype": {
           "version": "3.0.2",
           "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.0.2.tgz",
-          "integrity": "sha512-ofovWglpqoqbfLNOTBNZLSbMuGrblAf1efvvArGKOZMBrIoJeu5UsAipQolkijtyQx5MtAzT/J9IHj/CEY1mJw==",
-          "dev": true
+          "integrity": "sha512-ofovWglpqoqbfLNOTBNZLSbMuGrblAf1efvvArGKOZMBrIoJeu5UsAipQolkijtyQx5MtAzT/J9IHj/CEY1mJw=="
         }
       }
     },
@@ -8570,58 +8558,6 @@
         "requires-port": "^1.0.0"
       }
     },
-    "http-proxy-middleware": {
-      "version": "1.0.5",
-      "resolved": "https://registry.npmjs.org/http-proxy-middleware/-/http-proxy-middleware-1.0.5.tgz",
-      "integrity": "sha512-CKzML7u4RdGob8wuKI//H8Ein6wNTEQR7yjVEzPbhBLGdOfkfvgTnp2HLnniKBDP9QW4eG10/724iTWLBeER3g==",
-      "requires": {
-        "@types/http-proxy": "^1.17.4",
-        "http-proxy": "^1.18.1",
-        "is-glob": "^4.0.1",
-        "lodash": "^4.17.19",
-        "micromatch": "^4.0.2"
-      },
-      "dependencies": {
-        "braces": {
-          "version": "3.0.2",
-          "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
-          "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
-          "requires": {
-            "fill-range": "^7.0.1"
-          }
-        },
-        "fill-range": {
-          "version": "7.0.1",
-          "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
-          "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
-          "requires": {
-            "to-regex-range": "^5.0.1"
-          }
-        },
-        "is-number": {
-          "version": "7.0.0",
-          "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
-          "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng=="
-        },
-        "micromatch": {
-          "version": "4.0.2",
-          "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.2.tgz",
-          "integrity": "sha512-y7FpHSbMUMoyPbYUSzO6PaZ6FyRnQOpHuKwbo1G+Knck95XVU4QAiKdGEnj5wwoS7PlOgthX/09u5iFJ+aYf5Q==",
-          "requires": {
-            "braces": "^3.0.1",
-            "picomatch": "^2.0.5"
-          }
-        },
-        "to-regex-range": {
-          "version": "5.0.1",
-          "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
-          "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==",
-          "requires": {
-            "is-number": "^7.0.0"
-          }
-        }
-      }
-    },
     "http-signature": {
       "version": "1.2.0",
       "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz",
diff --git a/package.json b/package.json
index 9967bd3..8d886b8 100644
--- a/package.json
+++ b/package.json
@@ -48,7 +48,6 @@
     "@material-ui/core": "^4.11.0",
     "@types/styled-components": "^5.1.2",
     "axios": "^0.20.0",
-    "http-proxy-middleware": "^1.0.5",
     "react": "^16.13.1",
     "react-dom": "^16.13.1",
     "react-hook-form": "^6.5.3",
diff --git a/src/core/components/ContextTest.tsx b/src/core/components/ContextTest.tsx
index 9d99473..9251166 100644
--- a/src/core/components/ContextTest.tsx
+++ b/src/core/components/ContextTest.tsx
@@ -3,6 +3,7 @@ import { userContext } from '../context/UserContext';
 
 const ContextTest = () => {
   const { state: user } = useContext(userContext);
+  // eslint-disable-next-line no-console
   console.log(user.name);
   return <div>{user ? user.name : 'Not logged in!'}</div>;
 };
diff --git a/src/setupProxy.js b/src/setupProxy.js
deleted file mode 100644
index c5c25d0..0000000
--- a/src/setupProxy.js
+++ /dev/null
@@ -1,11 +0,0 @@
-const { createProxyMiddleware } = require('http-proxy-middleware');
-
-module.exports = (app) => {
-  app.use(
-    '/api',
-    createProxyMiddleware({
-      target: 'http://127.0.0.1:8000',
-      changeOrigin: true,
-    }),
-  );
-};
diff --git a/tools/local_proxy/Caddyfile b/tools/local_proxy/Caddyfile
new file mode 100644
index 0000000..0a389bc
--- /dev/null
+++ b/tools/local_proxy/Caddyfile
@@ -0,0 +1,13 @@
+# PORT
+:8080                                                            
+
+# Reverse proxy
+# rewrite
+
+# auth-service
+route /api/* {
+    #uri strip_prefix /api
+    reverse_proxy * 127.0.0.1:8000
+}
+
+reverse_proxy * 127.0.0.1:3000
-- 
GitLab