diff --git a/.env.example b/.env.example index b6307452..4177f686 100644 --- a/.env.example +++ b/.env.example @@ -17,9 +17,9 @@ LOG_LEVEL=info OPENCODE_SERVER_PORT=5551 OPENCODE_HOST=127.0.0.1 -# Optional - bearer password required to talk to the spawned OpenCode server. +# Required if OPENCODE_HOST is set to 0.0.0.0 or port 5551 is published. # When set, the backend spawns OpenCode with this password and attaches it to -# every proxied request. Leave unset to disable OpenCode-level auth. +# every proxied request. Leave unset only when OpenCode is bound to localhost. # OPENCODE_SERVER_PASSWORD= # Optional - import an existing standalone OpenCode install on first startup diff --git a/backend/src/services/opencode-single-server.ts b/backend/src/services/opencode-single-server.ts index 7907a0d8..4226b37f 100644 --- a/backend/src/services/opencode-single-server.ts +++ b/backend/src/services/opencode-single-server.ts @@ -24,6 +24,7 @@ import { patchOpenCodeConfig } from './proxy' const OPENCODE_SERVER_PORT = ENV.OPENCODE.PORT const OPENCODE_SERVER_HOST = ENV.OPENCODE.HOST +const OPENCODE_SERVER_CONNECT_HOST = OPENCODE_SERVER_HOST === '0.0.0.0' ? '127.0.0.1' : OPENCODE_SERVER_HOST const OPENCODE_SERVER_PUBLIC_URL = ENV.OPENCODE.PUBLIC_URL const OPENCODE_SERVER_PASSWORD = ENV.OPENCODE.SERVER_PASSWORD const OPENCODE_SERVER_USERNAME = ENV.OPENCODE.SERVER_USERNAME @@ -549,7 +550,7 @@ class OpenCodeServerManager { if (OPENCODE_BASIC_AUTH) { headers.Authorization = OPENCODE_BASIC_AUTH } - const response = await fetch(`http://${OPENCODE_SERVER_HOST}:${OPENCODE_SERVER_PORT}/doc`, { + const response = await fetch(`http://${OPENCODE_SERVER_CONNECT_HOST}:${OPENCODE_SERVER_PORT}/doc`, { signal: AbortSignal.timeout(3000), headers }) diff --git a/backend/src/services/proxy.ts b/backend/src/services/proxy.ts index 21a92788..db7a8408 100644 --- a/backend/src/services/proxy.ts +++ b/backend/src/services/proxy.ts @@ -3,7 +3,8 @@ import { ENV } from '@opencode-manager/shared/config/env' import { parseJsonc } from '@opencode-manager/shared/utils' import { timingSafeEqual } from 'crypto' -export const OPENCODE_SERVER_URL = `http://${ENV.OPENCODE.HOST}:${ENV.OPENCODE.PORT}` +const OPENCODE_CONNECT_HOST = ENV.OPENCODE.HOST === '0.0.0.0' ? '127.0.0.1' : ENV.OPENCODE.HOST +export const OPENCODE_SERVER_URL = `http://${OPENCODE_CONNECT_HOST}:${ENV.OPENCODE.PORT}` const OPENCODE_SERVER_PASSWORD = ENV.OPENCODE.SERVER_PASSWORD const OPENCODE_SERVER_USERNAME = ENV.OPENCODE.SERVER_USERNAME diff --git a/docker-compose.yml b/docker-compose.yml index 88f4caf7..bb2253ad 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,7 @@ services: container_name: opencode-manager ports: - "5003:5003" + - "5551:5551" - "5100:5100" - "5101:5101" - "5102:5102" @@ -15,6 +16,8 @@ services: - HOST=0.0.0.0 - PORT=5003 - OPENCODE_SERVER_PORT=5551 + - OPENCODE_HOST=0.0.0.0 + - OPENCODE_SERVER_PASSWORD=${OPENCODE_SERVER_PASSWORD:?Set OPENCODE_SERVER_PASSWORD before exposing OpenCode on port 5551} - DATABASE_PATH=/app/data/opencode.db - WORKSPACE_PATH=/workspace - PROCESS_START_WAIT_MS=2000 diff --git a/docs/configuration/docker.md b/docs/configuration/docker.md index ebc8c48c..7fc2f65d 100644 --- a/docs/configuration/docker.md +++ b/docs/configuration/docker.md @@ -38,6 +38,7 @@ services: container_name: opencode-manager ports: - "5003:5003" + - "5551:5551" - "5100:5100" - "5101:5101" - "5102:5102" @@ -47,6 +48,8 @@ services: - HOST=0.0.0.0 - PORT=5003 - OPENCODE_SERVER_PORT=5551 + - OPENCODE_HOST=0.0.0.0 + - OPENCODE_SERVER_PASSWORD=${OPENCODE_SERVER_PASSWORD:?Set OPENCODE_SERVER_PASSWORD before exposing OpenCode on port 5551} - DATABASE_PATH=/app/data/opencode.db - WORKSPACE_PATH=/workspace - PROCESS_START_WAIT_MS=2000