Skip to content

Fix proxy when specifying PROD=true#467

Merged
Wirasm merged 4 commits intocoleam00:mainfrom
michaelphines:fix-proxy
Aug 25, 2025
Merged

Fix proxy when specifying PROD=true#467
Wirasm merged 4 commits intocoleam00:mainfrom
michaelphines:fix-proxy

Conversation

@michaelphines
Copy link
Copy Markdown

@michaelphines michaelphines commented Aug 25, 2025

Pull Request

Summary

There appears to be a PROD env variable that was intended to make a Vite proxy handle API request. It's nearly hooked up, but the PROD environment variable isn't forwarded from the .env file, and the health endpoint is not using the proxied version of the URL.

Default behavior should remain unchanged, but it looks like in some cases the proxy was already used. This was true in places where getApiUrl was not used, for example: knowledgeBaseService uses API_BASE_URL and not API_FULL_URL

Changes Made

  • Update the health checker to use the /api/health version of the health endpoint rather than /health
  • Pass PROD through docker-compose and Vite
  • If "true", make the PROD setting override the VITE_API_URL (because VITE_API_URL always seems to be set)
  • Add HOST to allowedHosts

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring

Affected Services

  • Frontend (React UI)
  • Server (FastAPI backend)
  • MCP Server (Model Context Protocol)
  • Agents (PydanticAI service)
  • Database (migrations/schema)
  • Docker/Infrastructure
  • Documentation site

Testing

  • All existing tests pass
  • Added new tests for new functionality
  • Manually tested affected user flows
  • Docker builds succeed for all services

Test Evidence

Michael ~/projects/archon/archon-ui-main $ npm run test

> archon-ui@0.1.0 test
> vitest

[snip]

·············································································
JSON report written to /Users/Michael/projects/archon/archon-ui-main/public/test-results/test-results.json

 Test Files  7 passed (7)
      Tests  77 passed (77)
   Start at  00:33:13
   Duration  1.64s (transform 339ms, setup 1.02s, collect 359ms, tests 734ms, environment 2.01s, prepare 417ms)

Checklist

  • My code follows the service architecture patterns
  • If using an AI coding assistant, I used the CLAUDE.md rules
  • I have added tests that prove my fix/feature works
  • All new and existing tests pass locally
  • My changes generate no new warnings
  • I have updated relevant documentation
  • I have verified no regressions in existing features

Breaking Changes

None

Additional Notes

Given that the proxy here is already partially used even with PROD unset, I'm guessing it probably makes sense to make the PROD behavior the default (or even only) behavior. I didn't think that decision was appropriately in scope for this PR, however.

Summary by CodeRabbit

  • Bug Fixes
    • Updated health-check path for improved service compatibility.
    • Corrected production API URL resolution so production ignores custom API URL.
  • Development
    • Dev server accepts localhost, 127.0.0.1, and custom hostnames.
    • Exposes a runtime PROD flag for consistent environment handling.
  • Chores
    • Added PROD environment variable to compose and example config.
  • Tests
    • Adjusted tests to validate production behavior ignoring custom API URL.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Aug 25, 2025

Walkthrough

Health-check path changed to /api/health, API URL resolution now returns '' when PROD is true (ignoring VITE_API_URL), tests adjusted, Vite config adds allowedHosts and exposes import.meta.env.PROD, docker-compose and .env.example add a PROD variable.

Changes

Cohort / File(s) Summary
Health check endpoint
archon-ui-main/src/components/layouts/MainLayout.tsx
Health check path updated from /health to /api/health; request method, abort/signal, response handling, retry logic unchanged; trailing newline added.
API URL resolution
archon-ui-main/src/config/api.ts
getApiUrl() now checks PROD first and returns '' when PROD is true (ignores VITE_API_URL in production); non-prod logic (VITE_API_URL or constructed URL) unchanged.
API tests
archon-ui-main/test/config/api.test.ts
Production-mode test updated to set a dummy VITE_API_URL and assert getApiUrl() returns '' when PROD is true; minor formatting newline added.
Vite config
archon-ui-main/vite.config.ts
Added server.allowedHosts: [env.HOST, 'localhost', '127.0.0.1']; added 'import.meta.env.PROD': env.PROD === 'true' to define.
Compose env
docker-compose.yml
Added PROD=${PROD:-false} to archon-frontend service environment.
Env example
.env.example
Added PROD=false (with comment explaining proxy/port behavior) and minor formatting adjustments.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant App
  participant Config as getApiUrl()
  participant Env as env / import.meta.env

  User->>App: Load app / perform API call
  App->>Config: getApiUrl()
  Config->>Env: Read PROD, VITE_API_URL, PORT, window.location
  alt PROD === true
    note right of Config #DDEBF7: Production path\n(ignore VITE_API_URL)
    Config-->>App: return ''
  else PROD !== true
    alt VITE_API_URL set
      Config-->>App: return VITE_API_URL
    else
      Config-->>App: return constructed URL (window.location + PORT)
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I thump a note — the health check hops,
From /health to /api where it stops.
PROD flags rise, the hosts align,
Vite hums true, the configs shine.
A rabbit cheers for tidy change! 🥕

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
archon-ui-main/src/config/api.ts (1)

15-19: Resolution order change is correct; consider naming clarity

Checking PROD before VITE_API_URL achieves the intended “use proxy when PROD=true” behavior. One caution: you’re reusing the reserved Vite semantic flag name (PROD). That can be confusing since Vite already sets import.meta.env.PROD based on build mode.

If you want to avoid overloading semantics, rename the flag to VITE_USE_PROXY (or similar) and switch the check:

-  if (import.meta.env.PROD) {
+  if (import.meta.env.VITE_USE_PROXY) {
     return '';
   }

See paired suggestion in vite.config.ts.

archon-ui-main/vite.config.ts (2)

283-283: Filter falsy allowedHosts entries

env.HOST can be undefined; passing it through yields [undefined, 'localhost', '127.0.0.1'], which may trip type checks or cause noisy warnings.

-      allowedHosts: [env.HOST, 'localhost', '127.0.0.1'],
+      allowedHosts: [env.HOST, 'localhost', '127.0.0.1'].filter(Boolean),

312-313: Refactor suggestion: Don’t override import.meta.env.PROD, introduce a dedicated flag

Overriding Vite’s built-in import.meta.env.PROD can lead to mismatches between Vite’s actual build mode and code that relies on it. Since we only see it used in:

  • archon-ui-main/vite.config.ts (lines 312–313)
  • archon-ui-main/src/config/api.ts (the if (import.meta.env.PROD) check)

you can safely introduce a new flag—e.g. VITE_USE_PROXY—to drive proxy behavior:

• In vite.config.ts:

-      'import.meta.env.PROD': env.PROD === 'true',
+      'import.meta.env.VITE_USE_PROXY': env.PROD === 'true',

• In src/config/api.ts:

-  if (import.meta.env.PROD) {
+  if (import.meta.env.VITE_USE_PROXY) {
     return '';
   }

• Tests: we didn’t find any existing tests referencing import.meta.env.PROD. If you add or update tests around getApiUrl(), mock import.meta.env.VITE_USE_PROXY instead of PROD.

This change preserves Vite’s semantics for import.meta.env.PROD while clearly signaling when you’re forcing proxy mode.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 86dd1b0 and d5bbf58.

📒 Files selected for processing (5)
  • archon-ui-main/src/components/layouts/MainLayout.tsx (2 hunks)
  • archon-ui-main/src/config/api.ts (2 hunks)
  • archon-ui-main/test/config/api.test.ts (2 hunks)
  • archon-ui-main/vite.config.ts (2 hunks)
  • docker-compose.yml (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
{python/**/*.py,archon-ui-main/src/**/*.{ts,tsx,js,jsx}}

📄 CodeRabbit inference engine (CLAUDE.md)

{python/**/*.py,archon-ui-main/src/**/*.{ts,tsx,js,jsx}}: Remove dead code immediately; do not keep legacy/unused functions
Avoid comments that reference change history (e.g., LEGACY, CHANGED, REMOVED); keep comments focused on current functionality

Files:

  • archon-ui-main/src/components/layouts/MainLayout.tsx
  • archon-ui-main/src/config/api.ts
archon-ui-main/src/components/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place reusable UI components in archon-ui-main/src/components/

Files:

  • archon-ui-main/src/components/layouts/MainLayout.tsx
archon-ui-main/test/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place frontend tests under archon-ui-main/test/

Files:

  • archon-ui-main/test/config/api.test.ts
🧬 Code graph analysis (1)
archon-ui-main/src/components/layouts/MainLayout.tsx (1)
archon-ui-main/src/services/credentialsService.ts (1)
  • credentialsService (371-371)
🔇 Additional comments (5)
docker-compose.yml (1)

157-157: Healthcheck endpoints remain available at /health, so no Docker Compose changes are needed

I’ve confirmed that both services continue to expose a /health endpoint (with /api/health as an alias on the server), matching the existing Docker healthchecks.

• Server service
python/src/server/main.py defines @app.get("/health") (line 234) and @app.get("/api/health") (line 259).
python/Dockerfile.server healthcheck still calls http://localhost:${ARCHON_SERVER_PORT}/health.

• Agents service
python/src/agents/server.py defines @app.get("/health") (line 151).
python/Dockerfile.agents healthcheck still calls http://localhost:${ARCHON_AGENTS_PORT}/health.

Since /health is still supported, you can leave the - CMD .../health checks in docker-compose.yml as-is.

archon-ui-main/src/components/layouts/MainLayout.tsx (1)

215-215: No-op formatting change

Trailing newline/brace alignment only. Nothing to address.

archon-ui-main/test/config/api.test.ts (2)

35-44: LGTM: test asserts proxy-first behavior in “production” mode

The test now ensures VITE_API_URL is ignored when PROD is true, matching the new resolution order. Looks good.


238-238: No functional change

Trailing newline only.

archon-ui-main/src/config/api.ts (1)

61-65: Exports align; compute-on-import is fine with module resets

Computing API_FULL_URL/WS_URL at import time is acceptable since tests call vi.resetModules() to re-evaluate. No issues.

Comment on lines +48 to 51
const response = await fetch(`${credentialsService['baseUrl']}/api/health`, {
method: 'GET',
signal: controller.signal
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid double-prefixing /api by using centralized API base path

If credentialsService.baseUrl already contains /api, this becomes /api/api/health. Prefer the centralized helper to construct the base path.

Apply:

@@
-import { credentialsService } from '../../services/credentialsService';
+import { credentialsService } from '../../services/credentialsService';
+import { getApiBasePath } from '../../config/api';
@@
-        const response = await fetch(`${credentialsService['baseUrl']}/api/health`, {
+        const response = await fetch(`${getApiBasePath()}/health`, {
           method: 'GET',
           signal: controller.signal
         });

This keeps the health check correct regardless of whether you’re using a relative base or a full URL.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const response = await fetch(`${credentialsService['baseUrl']}/api/health`, {
method: 'GET',
signal: controller.signal
});
// archon-ui-main/src/components/layouts/MainLayout.tsx
import React from 'react';
import { credentialsService } from '../../services/credentialsService';
import { getApiBasePath } from '../../config/api';
// … other code …
const response = await fetch(`${getApiBasePath()}/health`, {
method: 'GET',
signal: controller.signal
});
// … other code …
🤖 Prompt for AI Agents
In archon-ui-main/src/components/layouts/MainLayout.tsx around lines 48 to 51,
the health check concatenates credentialsService.baseUrl with a hardcoded "/api"
which can produce "/api/api/health" when baseUrl already contains "/api"; change
the call to use the centralized API base-path helper (or derive a normalized
base without the "/api" prefix) and then append only "/health" so the final URL
is constructed consistently (e.g., use the app's API base helper to get baseUrl
and call `${apiBase}/health` or normalize credentialsService.baseUrl to strip
any trailing "/api" before appending "/health").

@Wirasm
Copy link
Copy Markdown
Collaborator

Wirasm commented Aug 25, 2025

thanks @michaelphines this looks great, but we should probably add the example variable with a description in the .env.example as well

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
.env.example (1)

39-42: Clarify boolean semantics and purpose of PROD to avoid confusion with Vite’s built-in PROD flag

Environment variables are strings; the code treats only the literal "true" as enabled. Also, naming this flag PROD can be confused with Vite’s compile-time import.meta.env.PROD. Since this file is the primary source of truth for users, tighten the docs here to spell out accepted values and the exact behavior (Vite proxying /api/* and getApiUrl() returning ''). Consider the wording tweak below; rename is optional for a later PR.

Apply this doc-only diff to make behavior explicit:

-# When enabled, PROD mode will proxy ARCHON_SERVER_PORT through ARCHON_UI_PORT. This exposes both the 
-# Archon UI and API through a single port. This is useful when deploying Archon behind a reverse 
-# proxy where you want to expose the frontend on a single external domain.
-PROD=false
+# Enable UI -> API proxying
+# Set to the string "true" (lowercase) to enable a Vite proxy that forwards /api/* from ARCHON_UI_PORT
+# to ARCHON_SERVER_PORT. This exposes both the Archon UI and API on a single external port/domain
+# (useful behind a reverse proxy). When PROD is "true", getApiUrl() returns an empty base URL and
+# ignores VITE_API_URL; API calls should use /api/* paths.
+# Any value other than "true" disables this behavior.
+PROD=false

If you want to further reduce ambiguity in a future PR (not required here), consider renaming to UI_PROXY_API or ENABLE_UI_PROXY and mapping it to import.meta.env.PROD in Vite config for backward compatibility.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d5bbf58 and 7a339dc.

📒 Files selected for processing (1)
  • .env.example (2 hunks)
🔇 Additional comments (1)
.env.example (1)

59-59: Minor comment formatting change is fine

No functional impact; aligns with surrounding comment style.

@Wirasm Wirasm merged commit 27fd562 into coleam00:main Aug 25, 2025
8 checks passed
POWERFULMOVES pushed a commit to POWERFULMOVES/PMOVES-Archon that referenced this pull request Feb 12, 2026
….1 (coleam00#467)

Bumps [aquasecurity/trivy-action](https://github.com/aquasecurity/trivy-action) from 0.24.0 to 0.33.1.
- [Release notes](https://github.com/aquasecurity/trivy-action/releases)
- [Commits](aquasecurity/trivy-action@0.24.0...0.33.1)

---
updated-dependencies:
- dependency-name: aquasecurity/trivy-action
  dependency-version: 0.33.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
coleam00 pushed a commit that referenced this pull request Apr 7, 2026
…rds (#467)

* fix: mock DB modules in github.test.ts to prevent phantom testuser/testrepo records

Self-filtering tests called handleWebhook() with mocked signature verification
but unmocked database modules. The code successfully wrote testuser/testrepo
codebase and conversation records to the real SQLite DB before failing on
the unmocked Octokit API call. The try/catch in the tests caught the Octokit
error but the DB writes had already persisted.

Added mock.module calls for @archon/core/db/conversations and
@archon/core/db/codebases, and strengthened the three affected tests
to assert that mockGetOrCreateConversation was called (proving the
code progressed past self-filtering).

* fix: also clear mockFindCodebaseByRepoUrl between self-filtering tests

Prevents stale call counts from leaking across tests.
Tyone88 pushed a commit to Tyone88/Archon that referenced this pull request Apr 16, 2026
…rds (coleam00#467)

* fix: mock DB modules in github.test.ts to prevent phantom testuser/testrepo records

Self-filtering tests called handleWebhook() with mocked signature verification
but unmocked database modules. The code successfully wrote testuser/testrepo
codebase and conversation records to the real SQLite DB before failing on
the unmocked Octokit API call. The try/catch in the tests caught the Octokit
error but the DB writes had already persisted.

Added mock.module calls for @archon/core/db/conversations and
@archon/core/db/codebases, and strengthened the three affected tests
to assert that mockGetOrCreateConversation was called (proving the
code progressed past self-filtering).

* fix: also clear mockFindCodebaseByRepoUrl between self-filtering tests

Prevents stale call counts from leaking across tests.
joaobmonteiro pushed a commit to joaobmonteiro/Archon that referenced this pull request Apr 26, 2026
…rds (coleam00#467)

* fix: mock DB modules in github.test.ts to prevent phantom testuser/testrepo records

Self-filtering tests called handleWebhook() with mocked signature verification
but unmocked database modules. The code successfully wrote testuser/testrepo
codebase and conversation records to the real SQLite DB before failing on
the unmocked Octokit API call. The try/catch in the tests caught the Octokit
error but the DB writes had already persisted.

Added mock.module calls for @archon/core/db/conversations and
@archon/core/db/codebases, and strengthened the three affected tests
to assert that mockGetOrCreateConversation was called (proving the
code progressed past self-filtering).

* fix: also clear mockFindCodebaseByRepoUrl between self-filtering tests

Prevents stale call counts from leaking across tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants