-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix the websocket connection error #378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,10 @@ const TARGET_SERVER_BASE_URL = process.env.SERVER_BASE_URL || 'http://localhost: | |
| const nextConfig: NextConfig = { | ||
| /* config options here */ | ||
| output: 'standalone', | ||
| /* expose SERVER_BASE_URL to bundle */ | ||
| env: { | ||
| SERVER_BASE_URL: TARGET_SERVER_BASE_URL, | ||
| }, | ||
|
Comment on lines
+9
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exposing For WebSocket connections on the client side, it's better to construct the URL dynamically based on // In client-side code
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsHost = window.location.host;
const wsUrl = `${wsProtocol}//${wsHost}`; // Adjust path as neededThis assumes your reverse proxy is configured to route WebSocket traffic from the same host to your backend service. I recommend removing this |
||
| // Optimize build for Docker | ||
| experimental: { | ||
| optimizePackageImports: ['@mermaid-js/mermaid', 'react-syntax-highlighter'], | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting
SERVER_BASE_URLhere hardcodeslocalhostinto the build artifact. This value is then passed to the client-side code via thenext.config.tschange, which will cause connection failures in any non-local deployment. The client's browser would try to connect to its ownlocalhostinstead of your server.This environment variable should be removed from the build stage. The client should determine the server URL dynamically.