From e8027ba515826f4dd187435591d3b54240a9bb09 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Mon, 28 Oct 2019 10:45:53 +0100 Subject: [PATCH] React UI: Serve React UI under /new (#6229) This makes React UI URLs look nicer than the previous /static/graph-new/app.html, but internally still serves all React UI files from the compiled-in static assets directory. Also, to allow future usage of the React / Reach router, we need to serve the main React app's index.html on certain sub-paths that correspond to current Prometheus's UI pages, instead of trying to serve actual files that match the provided path name. Signed-off-by: Julius Volz --- .gitignore | 2 +- Makefile | 2 +- scripts/build_react_app.sh | 6 ++---- web/ui/react-app/src/App.tsx | 2 +- web/ui/react-app/src/Navbar.tsx | 20 ++++++++++---------- web/ui/templates/graph.html | 2 +- web/web.go | 33 ++++++++++++++++++++++++++++++++- 7 files changed, 48 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 7bd3379e32..ff61ef8d04 100644 --- a/.gitignore +++ b/.gitignore @@ -18,5 +18,5 @@ benchmark.txt /documentation/examples/remote_storage/example_write_adapter/example_writer_adapter npm_licenses.tar.bz2 -/web/ui/static/graph-new +/web/ui/static/react /web/ui/assets_vfsdata.go diff --git a/Makefile b/Makefile index b3fa60f44b..2b511c97ea 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ DOCKER_ARCHS ?= amd64 armv7 arm64 REACT_APP_PATH = web/ui/react-app REACT_APP_SOURCE_FILES = $(wildcard $(REACT_APP_PATH)/public/* $(REACT_APP_PATH)/src/* $(REACT_APP_PATH)/tsconfig.json) -REACT_APP_OUTPUT_DIR = web/ui/static/graph-new +REACT_APP_OUTPUT_DIR = web/ui/static/react REACT_APP_NODE_MODULES_PATH = $(REACT_APP_PATH)/node_modules REACT_APP_NPM_LICENSES_TARBALL = "npm_licenses.tar.bz2" diff --git a/scripts/build_react_app.sh b/scripts/build_react_app.sh index 0117d6488d..68aea9f420 100755 --- a/scripts/build_react_app.sh +++ b/scripts/build_react_app.sh @@ -14,7 +14,5 @@ cd web/ui/react-app echo "building React app" PUBLIC_URL=. yarn build -rm -rf ../static/graph-new -mv build ../static/graph-new -# Prevent bad redirect due to Go HTTP router treating index.html specially. -mv ../static/graph-new/index.html ../static/graph-new/app.html +rm -rf ../static/react +mv build ../static/react diff --git a/web/ui/react-app/src/App.tsx b/web/ui/react-app/src/App.tsx index a88204a783..2df725db01 100755 --- a/web/ui/react-app/src/App.tsx +++ b/web/ui/react-app/src/App.tsx @@ -21,7 +21,7 @@ class App extends Component { <> - + diff --git a/web/ui/react-app/src/Navbar.tsx b/web/ui/react-app/src/Navbar.tsx index f54091817c..d6081d128e 100644 --- a/web/ui/react-app/src/Navbar.tsx +++ b/web/ui/react-app/src/Navbar.tsx @@ -17,26 +17,26 @@ const Navigation = () => { const [isOpen, setIsOpen] = useState(false); const toggle = () => setIsOpen(!isOpen); return ( - + - Prometheus + Prometheus