Skip to content

Conversation

@itsmylife44
Copy link

Summary

Fixes Docker web deployments where the UI cannot connect to the backend API.

Problem

When accessing AutoMaker via browser in Docker deployment, all API requests fail with CORS errors:

Cross-Origin Request Blocked: ... at http://localhost:3008/api/...

The UI is trying to reach localhost:3008 which, from the user's browser, refers to their local machine - not the Docker container.

Root Cause

The getServerUrl() function has web mode detection:

if (!window.electron) {
  return '';  // Use relative URLs in web mode
}

However, Vite's tree-shaking evaluates !window.electron as true during build (since window.electron is undefined in the build environment) and removes this branch entirely. The production bundle becomes:

O1=()=>mT||"http://localhost:3008"  // Always falls back to localhost

Solution

Use the in operator which Vite cannot statically analyze:

const isElectron = 'electron' in window && window.electron != null;
if (!isElectron) {
  return '';
}

This preserves the runtime check in the production bundle, allowing web mode to use relative URLs (/api/...) that nginx can proxy to the backend.

Docker Deployment Note

For Docker web deployments to work, nginx must proxy /api/ requests to the backend. The UI's docker-compose.yml should include nginx configuration like:

location /api/ {
    proxy_pass http://automaker-server:3008;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

Changes

  • apps/ui/src/lib/http-api-client.ts: Use in operator for Electron detection

Testing

  • Production build preserves web mode detection
  • Docker web UI connects to API via nginx proxy
  • Electron mode continues to work correctly

When building the UI for Docker deployment, Vite's tree-shaking removes
the web mode detection branch because it can statically evaluate
`!window.electron` as `true` during build (window.electron is undefined
in the build environment).

This causes the production bundle to always use `http://localhost:3008`
as the API URL, which fails in Docker web deployments where the browser
cannot reach localhost on the server.

The fix uses the `in` operator which Vite cannot statically analyze:

```typescript
// Before: Vite optimizes this away
if (!window.electron) { return ''; }

// After: Vite cannot determine result at build time
const isElectron = 'electron' in window && window.electron != null;
if (!isElectron) { return ''; }
```

In web mode, this returns an empty string, causing fetch requests to use
relative URLs (`/api/...`) which nginx can proxy to the backend server.
@coderabbitai
Copy link

coderabbitai bot commented Jan 30, 2026

Warning

Rate limit exceeded

@itsmylife44 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 26 minutes and 57 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @itsmylife44, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request provides a critical fix for Docker web deployments where the UI was unable to connect to the backend API due to Cross-Origin Request Blocked (CORS) errors. The issue stemmed from Vite's tree-shaking mechanism, which incorrectly optimized away the web mode detection logic during the build process. This resulted in the UI attempting to connect to localhost:3008 instead of using relative URLs that could be properly proxied. The solution involves modifying the getServerUrl() function to use the 'electron' in window operator, preventing Vite from statically analyzing and removing the necessary runtime check, thereby ensuring correct API URL resolution in web mode.

Highlights

  • Fixes Docker Web Deployments: Resolves critical CORS errors in Docker web deployments where the UI failed to connect to the backend API due to incorrect URL resolution, specifically trying to reach localhost:3008.
  • Prevents Vite Tree-shaking Issue: Addresses the root cause where Vite's static analysis incorrectly tree-shook the web mode detection logic (!window.electron), causing the production bundle to always fall back to a hardcoded localhost URL.
  • Robust Web Mode Detection: Implements a solution by using the 'electron' in window operator to ensure the web mode detection logic is preserved in the production bundle, allowing the UI to correctly use relative URLs for API requests which can then be proxied by nginx.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses a critical bug where Vite's tree-shaking was incorrectly removing code required for web deployments in Docker. The fix, which involves using the in operator to prevent static analysis at build time, is a clever and effective solution to ensure the runtime check for the Electron environment is preserved. The code change is well-contained and the accompanying comments clearly explain the rationale. This is a good fix that should resolve the CORS errors seen in Docker web deployments.

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.

1 participant