Conversation
Instead of relying in a specific configuration that must be known at runtime, but this client is fully static.
There was a problem hiding this comment.
Pull Request Overview
This PR replaces hardcoded service URLs with relative paths and proxy configurations, updates Nginx settings for routing, and streamlines environment variable usage across the frontend.
- Added Vite dev server proxy settings for API, Node-RED, and Grafana
- Introduced
GRAFANA_BASE_URLandNODERED_BASE_URLconstants and removed inline env var references - Updated Dockerfile, Nginx config template, and documentation to support dynamic proxy routing
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| vite.config.js | Adds proxy server settings for /api/v1, /node-red, and /grafana |
| src/pages/app/dashboard/DashboardDetails.jsx | Replaces inline import.meta.env with GRAFANA_BASE_URL import |
| src/pages/app/Mashups.jsx | Replaces inline Node-RED URL with NODERED_BASE_URL |
| src/pages/app/Editor.jsx | Uses NODERED_BASE_URL constant for iframe URL |
| src/components/dashboard/dashboard-panel.jsx | Swaps GRAFANA_URL env var for GRAFANA_BASE_URL |
| src/api/nodeRedClient.js | Exports NODERED_BASE_URL and updates axios client |
| src/api/grafanaClient.js | Defines GRAFANA_BASE_URL constant |
| src/api/axiosClient.js | Sets baseURL to /api/v1 instead of env var |
| README.md | Updates .env examples to use 127.0.0.1 and VITE_API_BASE_URL |
| Dockerfile | Switches Nginx config to a template path |
| .env.example | Aligns example URLs to 127.0.0.1 |
| .docker/nginx.conf | Adds proxy blocks for API, Node-RED, and Grafana |
Comments suppressed due to low confidence (1)
README.md:49
- The README mentions
VITE_API_BASE_URL, but the code and.env.exampleuseVITE_BASE_URL. Update the documentation to match the actual environment variable name (VITE_BASE_URL) or adjust the code to useVITE_API_BASE_URLfor consistency.
VITE_API_BASE_URL=http://127.0.0.1:3001/api/v1
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
aac0504 to
a190f96
Compare
ferferga
left a comment
There was a problem hiding this comment.
I fixed the eslint issues by fixing the environment that ESLint's uses for linting node-only files (I included the current ones that we are using, but the glob might need to be expanded in the future).
If the /backend needs the rewrite rule to work properly, I am certain that the others need that rule as well. Are you able to confirm that? If not, I will check in a couple of days, however grafana is difficult for me to verify.
Co-authored-by: Fernando Fernández <ferferga@hotmail.com>
60b16f8 to
193451f
Compare
By using nginx and vite as a proxy, the frontend will always be able to locate the services it depends on, regardless of the setup of the consumer.
Be aware that the container doesn't work now if the enviornmnet variables have not been defined
---- Copilot summary below ----
This pull request introduces changes to improve the handling of environment-based URLs and proxy configurations, simplifying the codebase and enhancing maintainability. Key updates include replacing hardcoded URLs with relative paths, adding proxy configurations in
vite.config.js, and updating Nginx settings to support these changes.Proxy and URL Handling Improvements:
Environment-based URLs replaced with relative paths: Updated the
baseURLinaxiosClient.js,grafanaClient.js, andnodeRedClient.jsto use relative paths (/api/v1,/grafana,/node-red) instead of hardcoded environment variables. This change simplifies configuration and aligns with the new proxy setup. [1] [2] [3]Proxy configuration added in
vite.config.js: Introduced proxy settings for/api/v1,/node-red, and/grafanato route requests to the appropriate backend services based on environment variables. This ensures seamless development and production setups.Nginx Configuration Updates:
locationblocks in.docker/nginx.confto handle/api/v1,/node-red, and/grafanaroutes, including headers for proxy support and error interception. This enables proper routing for backend services.Codebase Simplification:
GRAFANA_BASE_URL,NODERED_BASE_URL) in components likeDashboardPanel,Editor,Mashups, andDashboardDetails. This improves readability and consistency across the codebase. [1] [2] [3] [4] [5] [6] [7] [8] [9]Documentation and Example Updates:
.env.exampleandREADME.mdto reflect the new base URLs (127.0.0.1instead oflocalhost) for consistency with proxy configurations. [1] [2]Dockerfile Adjustment:
Dockerfileto use a template (default.conf.template) instead of a static file, allowing for dynamic configuration in containerized environments.