From ee1007f8af9b244faef1860d7304f16891e04e91 Mon Sep 17 00:00:00 2001 From: chen zhang Date: Mon, 4 Aug 2025 17:34:17 +0800 Subject: [PATCH 1/2] rename SERVER_BASE_URL to NEXT_PUBLIC_SERVER_BASE_URL as previous one be blocked by nodejs(without NEXT_PUBLIC* prefix) --- Dockerfile | 2 +- Dockerfile-ollama-local | 2 +- README.md | 4 ++-- docker-compose.yml | 2 +- next.config.ts | 2 +- src/app/[owner]/[repo]/page.tsx | 4 ++-- src/app/[owner]/[repo]/slides/page.tsx | 4 ++-- src/app/[owner]/[repo]/workshop/page.tsx | 2 +- src/app/api/auth/status/route.ts | 2 +- src/app/api/auth/validate/route.ts | 2 +- src/app/api/chat/stream/route.ts | 4 ++-- src/app/api/models/config/route.ts | 2 +- src/utils/websocketClient.ts | 2 +- 13 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index ab818ef5..638d08b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/Dockerfile-ollama-local b/Dockerfile-ollama-local index 92a254fa..a52c9a44 100644 --- a/Dockerfile-ollama-local +++ b/Dockerfile-ollama-local @@ -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 diff --git a/README.md b/README.md index 538fa647..d401d691 100644 --- a/README.md +++ b/README.md @@ -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`. | diff --git a/docker-compose.yml b/docker-compose.yml index 08953808..3e12e6fa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: diff --git a/next.config.ts b/next.config.ts index 539857b6..7ca6dbf0 100644 --- a/next.config.ts +++ b/next.config.ts @@ -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'; const nextConfig: NextConfig = { /* config options here */ diff --git a/src/app/[owner]/[repo]/page.tsx b/src/app/[owner]/[repo]/page.tsx index 80e403b8..7b3c27aa 100644 --- a/src/app/[owner]/[repo]/page.tsx +++ b/src/app/[owner]/[repo]/page.tsx @@ -518,7 +518,7 @@ Remember: try { // Create WebSocket URL from the server base URL - const serverBaseUrl = process.env.SERVER_BASE_URL || 'http://localhost:8001'; + const serverBaseUrl = process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001'; const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws')? serverBaseUrl.replace(/^https/, 'wss'): serverBaseUrl.replace(/^http/, 'ws'); const wsUrl = `${wsBaseUrl}/ws/chat`; @@ -815,7 +815,7 @@ IMPORTANT: try { // Create WebSocket URL from the server base URL - const serverBaseUrl = process.env.SERVER_BASE_URL || 'http://localhost:8001'; + const serverBaseUrl = process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001'; const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws')? serverBaseUrl.replace(/^https/, 'wss'): serverBaseUrl.replace(/^http/, 'ws'); const wsUrl = `${wsBaseUrl}/ws/chat`; diff --git a/src/app/[owner]/[repo]/slides/page.tsx b/src/app/[owner]/[repo]/slides/page.tsx index 8b487fa1..94ca972b 100644 --- a/src/app/[owner]/[repo]/slides/page.tsx +++ b/src/app/[owner]/[repo]/slides/page.tsx @@ -265,7 +265,7 @@ 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 serverBaseUrl = process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001'; const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws')? serverBaseUrl.replace(/^https/, 'wss'): serverBaseUrl.replace(/^http/, 'ws'); const wsUrl = `${wsBaseUrl}/ws/chat`; @@ -541,7 +541,7 @@ 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 serverBaseUrl = process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001'; const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws')? serverBaseUrl.replace(/^https/, 'wss'): serverBaseUrl.replace(/^http/, 'ws'); const wsUrl = `${wsBaseUrl}/ws/chat`; diff --git a/src/app/[owner]/[repo]/workshop/page.tsx b/src/app/[owner]/[repo]/workshop/page.tsx index 7a1e29c7..7efa1fdf 100644 --- a/src/app/[owner]/[repo]/workshop/page.tsx +++ b/src/app/[owner]/[repo]/workshop/page.tsx @@ -317,7 +317,7 @@ 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 serverBaseUrl = process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001'; const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws')? serverBaseUrl.replace(/^https/, 'wss'): serverBaseUrl.replace(/^http/, 'ws'); const wsUrl = `${wsBaseUrl}/ws/chat`; diff --git a/src/app/api/auth/status/route.ts b/src/app/api/auth/status/route.ts index 601bb30b..b0e6fcd0 100644 --- a/src/app/api/auth/status/route.ts +++ b/src/app/api/auth/status/route.ts @@ -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 { diff --git a/src/app/api/auth/validate/route.ts b/src/app/api/auth/validate/route.ts index 0a9b7c0a..5f7d9312 100644 --- a/src/app/api/auth/validate/route.ts +++ b/src/app/api/auth/validate/route.ts @@ -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 { diff --git a/src/app/api/chat/stream/route.ts b/src/app/api/chat/stream/route.ts index 544c5d1e..a6961117 100644 --- a/src/app/api/chat/stream/route.ts +++ b/src/app/api/chat/stream/route.ts @@ -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'; // 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 @@ -110,4 +110,4 @@ export async function OPTIONS() { 'Access-Control-Allow-Headers': 'Content-Type, Authorization', // Adjust as per client's request headers }, }); -} \ No newline at end of file +} diff --git a/src/app/api/models/config/route.ts b/src/app/api/models/config/route.ts index 802df221..e9b24aad 100644 --- a/src/app/api/models/config/route.ts +++ b/src/app/api/models/config/route.ts @@ -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 { diff --git a/src/utils/websocketClient.ts b/src/utils/websocketClient.ts index b29c1b10..1075c3c4 100644 --- a/src/utils/websocketClient.ts +++ b/src/utils/websocketClient.ts @@ -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 = () => { From bbc60d88a3c4cfaab651e17c2d6a93afcbe8a48f Mon Sep 17 00:00:00 2001 From: chen zhang Date: Mon, 4 Aug 2025 18:04:43 +0800 Subject: [PATCH 2/2] fix comment --- src/app/[owner]/[repo]/page.tsx | 4 ++-- src/app/[owner]/[repo]/slides/page.tsx | 4 ++-- src/app/[owner]/[repo]/workshop/page.tsx | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app/[owner]/[repo]/page.tsx b/src/app/[owner]/[repo]/page.tsx index 7b3c27aa..cb7241e6 100644 --- a/src/app/[owner]/[repo]/page.tsx +++ b/src/app/[owner]/[repo]/page.tsx @@ -519,7 +519,7 @@ Remember: try { // Create WebSocket URL from the server base URL const serverBaseUrl = process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001'; - const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws')? serverBaseUrl.replace(/^https/, 'wss'): serverBaseUrl.replace(/^http/, 'ws'); + const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws'); const wsUrl = `${wsBaseUrl}/ws/chat`; // Create a new WebSocket connection @@ -816,7 +816,7 @@ IMPORTANT: try { // Create WebSocket URL from the server base URL const serverBaseUrl = process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001'; - const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws')? serverBaseUrl.replace(/^https/, 'wss'): serverBaseUrl.replace(/^http/, 'ws'); + const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws'); const wsUrl = `${wsBaseUrl}/ws/chat`; // Create a new WebSocket connection diff --git a/src/app/[owner]/[repo]/slides/page.tsx b/src/app/[owner]/[repo]/slides/page.tsx index 94ca972b..9da9d37c 100644 --- a/src/app/[owner]/[repo]/slides/page.tsx +++ b/src/app/[owner]/[repo]/slides/page.tsx @@ -266,7 +266,7 @@ 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.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001'; - const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws')? serverBaseUrl.replace(/^https/, 'wss'): serverBaseUrl.replace(/^http/, 'ws'); + const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws'); const wsUrl = `${wsBaseUrl}/ws/chat`; // Create a new WebSocket connection @@ -542,7 +542,7 @@ 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.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001'; - const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws')? serverBaseUrl.replace(/^https/, 'wss'): serverBaseUrl.replace(/^http/, 'ws'); + const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws'); const wsUrl = `${wsBaseUrl}/ws/chat`; // Create a new WebSocket connection diff --git a/src/app/[owner]/[repo]/workshop/page.tsx b/src/app/[owner]/[repo]/workshop/page.tsx index 7efa1fdf..a43fddac 100644 --- a/src/app/[owner]/[repo]/workshop/page.tsx +++ b/src/app/[owner]/[repo]/workshop/page.tsx @@ -318,7 +318,7 @@ Make the workshop content in ${language === 'en' ? 'English' : try { // Create WebSocket URL from the server base URL const serverBaseUrl = process.env.NEXT_PUBLIC_SERVER_BASE_URL || 'http://localhost:8001'; - const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws')? serverBaseUrl.replace(/^https/, 'wss'): serverBaseUrl.replace(/^http/, 'ws'); + const wsBaseUrl = serverBaseUrl.replace(/^http/, 'ws'); const wsUrl = `${wsBaseUrl}/ws/chat`; // Create a new WebSocket connection