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..cb7241e6 100644 --- a/src/app/[owner]/[repo]/page.tsx +++ b/src/app/[owner]/[repo]/page.tsx @@ -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 @@ -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 diff --git a/src/app/[owner]/[repo]/slides/page.tsx b/src/app/[owner]/[repo]/slides/page.tsx index 8b487fa1..9da9d37c 100644 --- a/src/app/[owner]/[repo]/slides/page.tsx +++ b/src/app/[owner]/[repo]/slides/page.tsx @@ -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 @@ -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 diff --git a/src/app/[owner]/[repo]/workshop/page.tsx b/src/app/[owner]/[repo]/workshop/page.tsx index 7a1e29c7..a43fddac 100644 --- a/src/app/[owner]/[repo]/workshop/page.tsx +++ b/src/app/[owner]/[repo]/workshop/page.tsx @@ -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 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 = () => {