|
| 1 | +# Proxy Configuration |
| 2 | + |
| 3 | +This directory contains configurations for running the HyperDX frontend behind a |
| 4 | +reverse proxy that serves the application under a specific subpath. This is |
| 5 | +useful for deployments where HyperDX is not at the root of a domain (e.g., |
| 6 | +`http://example.com/hyperdx`). |
| 7 | + |
| 8 | +We provide configurations for two popular reverse proxies: |
| 9 | + |
| 10 | +- [Nginx](./nginx/nginx.conf.template) |
| 11 | +- [Traefik](./traefik/config.yml) |
| 12 | + |
| 13 | +## Environment Variables |
| 14 | + |
| 15 | +To configure the subpath, you need to set the following environment variables in |
| 16 | +your `.env` file. |
| 17 | + |
| 18 | +### `HYPERDX_BASE_PATH` and `NEXT_PUBLIC_HYPERDX_BASE_PATH` |
| 19 | + |
| 20 | +To serve the application from a subpath, two environment variables must be set |
| 21 | +to the **same value**: |
| 22 | + |
| 23 | +1. `HYPERDX_BASE_PATH`: This is used by the reverse proxy (Nginx or Traefik) to |
| 24 | + handle path routing and rewriting. |
| 25 | +2. `NEXT_PUBLIC_HYPERDX_BASE_PATH`: This is used by the Next.js application to |
| 26 | + generate correct asset links and API routes. |
| 27 | + |
| 28 | +- The value **must** start with a `/` if it's not an empty string (ex: |
| 29 | + `/hyperdx`). |
| 30 | +- If you want to serve from the root, you can omit these variables or set them |
| 31 | + to `/`. |
| 32 | + |
| 33 | +### `FRONTEND_URL` |
| 34 | + |
| 35 | +This variable should be set to the full public URL of the frontend, including |
| 36 | +the subpath. The API server uses this URL for various purposes such as |
| 37 | +generating absolute URLs for redirects, links in emails, or alerts. |
| 38 | + |
| 39 | +- It should be a full URL, including the protocol (`http` or `https`). |
| 40 | +- It should include the subpath defined in `HYPERDX_BASE_PATH`. |
| 41 | + |
| 42 | +**Example `.env` Configuration:** |
| 43 | + |
| 44 | +For local development with the subpath `/hyperdx`, your configuration would look |
| 45 | +like this: |
| 46 | + |
| 47 | +``` |
| 48 | +HYPERDX_BASE_PATH=/hyperdx |
| 49 | +NEXT_PUBLIC_HYPERDX_BASE_PATH=/hyperdx |
| 50 | +FRONTEND_URL=http://localhost:4040/hyperdx |
| 51 | +``` |
| 52 | + |
| 53 | +## How It Works |
| 54 | + |
| 55 | +The proxy configurations are designed to handle subpath routing with minimal |
| 56 | +changes to the application code. Here's a high-level overview of the logic: |
| 57 | + |
| 58 | +1. **Root Redirect**: If a subpath is configured (e.g., `/hyperdx`), any |
| 59 | + requests to the root (`/`) are automatically redirected to that subpath. |
| 60 | + This ensures users always land on the correct URL. |
| 61 | + |
| 62 | +2. **Path Rewriting**: The application's frontend code sometimes makes requests |
| 63 | + to root-level paths (e.g., `/api/...` or `/_next/...`). The proxy intercepts |
| 64 | + these requests, prepends the configured subpath, and forwards them to the |
| 65 | + Next.js server. For example, a request for `/_next/static/chunk.js` becomes |
| 66 | + a request for `/hyperdx/_next/static/chunk.js` before being sent to the |
| 67 | + application. |
| 68 | + |
| 69 | +3. **Direct Proxy**: Any requests that already include the correct subpath are |
| 70 | + passed directly to the Next.js application, which is configured via |
| 71 | + `basePath` to handle them correctly. |
| 72 | + |
| 73 | +This setup allows the frontend application to be developed as if it were running |
| 74 | +at the root, while the proxy transparently manages the subpath routing. |
0 commit comments