Skip to content

feat: use nginx as a proxy to the rest of the services - #48

Open
ferferga wants to merge 27 commits into
mainfrom
fix-endpoints
Open

ferferga wants to merge 27 commits into
mainfrom
fix-endpoints

Conversation

@ferferga

@ferferga ferferga commented Jun 4, 2025

Copy link
Copy Markdown
Member

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 baseURL in axiosClient.js, grafanaClient.js, and nodeRedClient.js to 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 /grafana to route requests to the appropriate backend services based on environment variables. This ensures seamless development and production setups.

Nginx Configuration Updates:

  • Nginx settings updated for proxy routing: Added new location blocks in .docker/nginx.conf to handle /api/v1, /node-red, and /grafana routes, including headers for proxy support and error interception. This enables proper routing for backend services.

Codebase Simplification:

  • Environment variable usage removed from components: Replaced direct usage of environment variables with constants (GRAFANA_BASE_URL, NODERED_BASE_URL) in components like DashboardPanel, Editor, Mashups, and DashboardDetails. This improves readability and consistency across the codebase. [1] [2] [3] [4] [5] [6] [7] [8] [9]

Documentation and Example Updates:

  • Environment variable examples updated: Updated .env.example and README.md to reflect the new base URLs (127.0.0.1 instead of localhost) for consistency with proxy configurations. [1] [2]

Dockerfile Adjustment:

  • Nginx configuration file path changed: Modified the path for Nginx configuration in the Dockerfile to use a template (default.conf.template) instead of a static file, allowing for dynamic configuration in containerized environments.

ferferga added 2 commits June 4, 2025 17:41
Instead of relying in a specific configuration that
must be known at runtime, but this client is fully static.
@github-actions github-actions Bot added the 😎 size/m Pull request size M label Jun 4, 2025

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_URL and NODERED_BASE_URL constants 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.example use VITE_BASE_URL. Update the documentation to match the actual environment variable name (VITE_BASE_URL) or adjust the code to use VITE_API_BASE_URL for consistency.
VITE_API_BASE_URL=http://127.0.0.1:3001/api/v1

Comment thread Dockerfile
Comment thread .docker/nginx.conf Outdated
Comment thread vite.config.js
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@alvarobernal2412 alvarobernal2412 added 🐳 Dockerize Indicates that the pull request is going to be dockerized and removed 🐳 Dockerize Indicates that the pull request is going to be dockerized labels Jun 12, 2025

@ferferga ferferga left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread vite.config.js Outdated
@github-actions github-actions Bot added 📝 Documentation Improvements or additions to documentation ⚙️ Configuration Indicates the scope is related to the configuration 🐳 Build 🤯 size/xl Pull request size XL labels Nov 19, 2025
@alvarobernal2412
alvarobernal2412 force-pushed the fix-endpoints branch 2 times, most recently from 60b16f8 to 193451f Compare November 19, 2025 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐳 Build ⚙️ Configuration Indicates the scope is related to the configuration 🐳 Dockerize Indicates that the pull request is going to be dockerized 📝 Documentation Improvements or additions to documentation 😎 size/m Pull request size M 🤯 size/xl Pull request size XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants