Skip to content

rename SERVER_BASE_URL to NEXT_PUBLIC_SERVER_BASE_URL as previous one… #299

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ exit $?' > /app/start.sh && chmod +x /app/start.sh
# Set environment variables
ENV PORT=8001
ENV NODE_ENV=production
ENV SERVER_BASE_URL=http://localhost:${PORT:-8001}
ENV NEXT_PUBLIC_SERVER_BASE_URL=http://localhost:${PORT:-8001}

# Create empty .env file (will be overridden if one exists at runtime)
RUN touch .env
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-ollama-local
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ exit $?' > /app/start.sh && chmod +x /app/start.sh
# Set environment variables
ENV PORT=8001
ENV NODE_ENV=production
ENV SERVER_BASE_URL=http://localhost:${PORT:-8001}
ENV NEXT_PUBLIC_SERVER_BASE_URL=http://localhost:${PORT:-8001}

# Create empty .env file (will be overridden if one exists at runtime)
RUN touch .env
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ docker-compose up
| `AZURE_OPENAI_ENDPOINT` | Azure OpenAI endpoint | No | Required only if you want to use Azure OpenAI models |
| `AZURE_OPENAI_VERSION` | Azure OpenAI version | No | Required only if you want to use Azure OpenAI models |
| `OLLAMA_HOST` | Ollama Host (default: http://localhost:11434) | No | Required only if you want to use external Ollama server |
| `PORT` | Port for the API server (default: 8001) | No | If you host API and frontend on the same machine, make sure change port of `SERVER_BASE_URL` accordingly |
| `SERVER_BASE_URL` | Base URL for the API server (default: http://localhost:8001) | No |
| `PORT` | Port for the API server (default: 8001) | No | If you host API and frontend on the same machine, make sure change port of `NEXT_PUBLIC_SERVER_BASE_URL` accordingly |
| `NEXT_PUBLIC_SERVER_BASE_URL` | Base URL for the API server (default: http://localhost:8001) | No |
| `DEEPWIKI_AUTH_MODE` | Set to `true` or `1` to enable authorization mode. | No | Defaults to `false`. If enabled, `DEEPWIKI_AUTH_CODE` is required. |
| `DEEPWIKI_AUTH_CODE` | The secret code required for wiki generation when `DEEPWIKI_AUTH_MODE` is enabled. | No | Only used if `DEEPWIKI_AUTH_MODE` is `true` or `1`. |

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
environment:
- PORT=${PORT:-8001}
- NODE_ENV=production
- SERVER_BASE_URL=http://localhost:${PORT:-8001}
- NEXT_PUBLIC_SERVER_BASE_URL=http://localhost:${PORT:-8001}
- LOG_LEVEL=${LOG_LEVEL:-INFO}
- LOG_FILE_PATH=${LOG_FILE_PATH:-api/logs/application.log}
volumes:
Expand Down
2 changes: 1 addition & 1 deletion next.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { NextConfig } from "next";

const TARGET_SERVER_BASE_URL = process.env.SERVER_BASE_URL || 'http://localhost:8001';
const TARGET_SERVER_BASE_URL = process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001';
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

It's generally better to use a separate, non-public environment variable for server-side configurations like this one. The NEXT_PUBLIC_ prefix is intended to expose variables to the browser, which isn't necessary for server-side code like next.config.ts and API routes.

This separation allows for more flexible deployment scenarios. For example, you could use an internal service URL (e.g., http://api-service:8001) on the server while the client uses a public-facing URL.

To improve this, you could prioritize a server-specific variable and fall back to the public one. This would make the configuration more robust and align with best practices.

Suggested change
const TARGET_SERVER_BASE_URL = process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001';
const TARGET_SERVER_BASE_URL = process.env.SERVER_BASE_URL || process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001';


const nextConfig: NextConfig = {
/* config options here */
Expand Down
8 changes: 4 additions & 4 deletions src/app/[owner]/[repo]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,8 @@ Remember:

try {
// Create WebSocket URL from the server base URL
const serverBaseUrl = process.env.SERVER_BASE_URL || 'http://localhost:8001';
const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws')? serverBaseUrl.replace(/^https/, 'wss'): serverBaseUrl.replace(/^http/, 'ws');
const serverBaseUrl = process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001';
const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws');
const wsUrl = `${wsBaseUrl}/ws/chat`;

// Create a new WebSocket connection
Expand Down Expand Up @@ -815,8 +815,8 @@ IMPORTANT:

try {
// Create WebSocket URL from the server base URL
const serverBaseUrl = process.env.SERVER_BASE_URL || 'http://localhost:8001';
const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws')? serverBaseUrl.replace(/^https/, 'wss'): serverBaseUrl.replace(/^http/, 'ws');
const serverBaseUrl = process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001';
const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws');
const wsUrl = `${wsBaseUrl}/ws/chat`;

// Create a new WebSocket connection
Expand Down
8 changes: 4 additions & 4 deletions src/app/[owner]/[repo]/slides/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ Give me the numbered list with brief descriptions for each slide. Be creative bu

try {
// Create WebSocket URL from the server base URL
const serverBaseUrl = process.env.SERVER_BASE_URL || 'http://localhost:8001';
const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws')? serverBaseUrl.replace(/^https/, 'wss'): serverBaseUrl.replace(/^http/, 'ws');
const serverBaseUrl = process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001';
const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws');
const wsUrl = `${wsBaseUrl}/ws/chat`;

// Create a new WebSocket connection
Expand Down Expand Up @@ -541,8 +541,8 @@ Please return ONLY the HTML with no markdown formatting or code blocks. Just the

try {
// Create WebSocket URL from the server base URL
const serverBaseUrl = process.env.SERVER_BASE_URL || 'http://localhost:8001';
const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws')? serverBaseUrl.replace(/^https/, 'wss'): serverBaseUrl.replace(/^http/, 'ws');
const serverBaseUrl = process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001';
const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws');
const wsUrl = `${wsBaseUrl}/ws/chat`;

// Create a new WebSocket connection
Expand Down
4 changes: 2 additions & 2 deletions src/app/[owner]/[repo]/workshop/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ Make the workshop content in ${language === 'en' ? 'English' :

try {
// Create WebSocket URL from the server base URL
const serverBaseUrl = process.env.SERVER_BASE_URL || 'http://localhost:8001';
const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws')? serverBaseUrl.replace(/^https/, 'wss'): serverBaseUrl.replace(/^http/, 'ws');
const serverBaseUrl = process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001';
const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws');
const wsUrl = `${wsBaseUrl}/ws/chat`;

// Create a new WebSocket connection
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/auth/status/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextResponse } from "next/server";

const TARGET_SERVER_BASE_URL = process.env.SERVER_BASE_URL || 'http://localhost:8001';
const TARGET_SERVER_BASE_URL = process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001';

export async function GET() {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/auth/validate/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextRequest, NextResponse } from "next/server";

const TARGET_SERVER_BASE_URL = process.env.SERVER_BASE_URL || 'http://localhost:8001';
const TARGET_SERVER_BASE_URL = process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001';

export async function POST(request: NextRequest) {
try {
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/chat/stream/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from 'next/server';

// The target backend server base URL, derived from environment variable or defaulted.
// This should match the logic in your frontend's page.tsx for consistency.
const TARGET_SERVER_BASE_URL = process.env.SERVER_BASE_URL || 'http://localhost:8001';
const TARGET_SERVER_BASE_URL = process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001';
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This API route is server-side code and doesn't strictly need to use a NEXT_PUBLIC_ prefixed environment variable.

For better separation of concerns and deployment flexibility, it's recommended to use a server-only environment variable for server-to-server communication. This prevents accidentally exposing server-internal configuration to the client and makes the architecture clearer.

Suggested change
const TARGET_SERVER_BASE_URL = process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001';
const TARGET_SERVER_BASE_URL = process.env.SERVER_BASE_URL || process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001';


// This is a fallback HTTP implementation that will be used if WebSockets are not available
// or if there's an error with the WebSocket connection
Expand Down Expand Up @@ -110,4 +110,4 @@ export async function OPTIONS() {
'Access-Control-Allow-Headers': 'Content-Type, Authorization', // Adjust as per client's request headers
},
});
}
}
2 changes: 1 addition & 1 deletion src/app/api/models/config/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextResponse } from 'next/server';

// The target backend server base URL, derived from environment variable or defaulted.
const TARGET_SERVER_BASE_URL = process.env.SERVER_BASE_URL || 'http://localhost:8001';
const TARGET_SERVER_BASE_URL = process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001';

export async function GET() {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/websocketClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

// Get the server base URL from environment or use default
const SERVER_BASE_URL = process.env.SERVER_BASE_URL || 'http://localhost:8001';
const SERVER_BASE_URL = process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001';

// Convert HTTP URL to WebSocket URL
const getWebSocketUrl = () => {
Expand Down