Skip to content

Conversation

@hass-demacia
Copy link

@hass-demacia hass-demacia commented Oct 20, 2025

#132

Next.js doesn't expose parameters into bundle.js default.

By adding the NEXT_PUBLIC_ prefix to an environment variable, it will be exposed to the browser.
Or adding the parameter in the next.config.js.

next.config.js environment-variables

Expose SERVER_BASE_URL in the environment variables.
Set SERVER_BASE_URL environment variable for client bundle.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @hass-demacia, 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 resolves a websocket connection error by correctly exposing the SERVER_BASE_URL environment variable to the Next.js client-side bundle. The changes involve configuring this variable in the Dockerfile to ensure it's available during the build process and explicitly adding it to the env object in next.config.ts. This ensures the client-side application has the correct server base URL, preventing connection failures.

Highlights

  • Environment Variable Exposure: Ensured the SERVER_BASE_URL environment variable is correctly exposed to the Next.js client-side bundle, addressing a common issue where Next.js does not expose parameters into bundle.js by default.
  • Dockerfile Configuration: Added the SERVER_BASE_URL environment variable directly into the Dockerfile, setting it before the npm run build step to ensure it's injected into the bundle during the build process.
  • Next.js Configuration Update: Modified next.config.ts to explicitly include SERVER_BASE_URL within the env object, making it accessible to the client-side application.
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 attempts to fix a WebSocket connection issue by exposing SERVER_BASE_URL to the client. While the intent is correct, the implementation hardcodes http://localhost:8001 as the server URL in the client-side bundle. This is a critical flaw that will prevent the application from working in any deployed environment outside of a local machine. My review provides detailed feedback on why this is an issue and suggests a more robust, dynamic approach where the client constructs the server URL based on its own location, which is standard practice for web applications.

ENV NODE_OPTIONS="--max-old-space-size=4096"
ENV NEXT_TELEMETRY_DISABLED=1
# `next build` inject `SERVER_BASE_URL` into bundle.js for client, once code is builded, bundle can't be modify by .env or ENV parameters.
ENV SERVER_BASE_URL="http://localhost:${PORT:-8001}"
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

Setting SERVER_BASE_URL here hardcodes localhost into the build artifact. This value is then passed to the client-side code via the next.config.ts change, which will cause connection failures in any non-local deployment. The client's browser would try to connect to its own localhost instead of your server.

This environment variable should be removed from the build stage. The client should determine the server URL dynamically.

Comment on lines +9 to +11
env: {
SERVER_BASE_URL: TARGET_SERVER_BASE_URL,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

Exposing TARGET_SERVER_BASE_URL to the client bundle is problematic because it will contain a localhost URL baked in at build time. This will cause connection errors for users in a deployed environment.

For WebSocket connections on the client side, it's better to construct the URL dynamically based on window.location. This avoids hardcoding hostnames. For example:

// In client-side code
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsHost = window.location.host;
const wsUrl = `${wsProtocol}//${wsHost}`; // Adjust path as needed

This assumes your reverse proxy is configured to route WebSocket traffic from the same host to your backend service.

I recommend removing this env block. The SERVER_BASE_URL environment variable should be used for server-side logic only (like the existing rewrites), where it can be configured at runtime.

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