mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
refactor: consolidate environment config and API handling
- Update database paths and port configuration - Remove backend config.ts and sessions route - Add mobile file preview and files API - Clean up shared constants and provider hooks
This commit is contained in:
1 parent
0db354048d
commit
8a56bc208d
32 files changed
+301
-512
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { promises as fs } from 'fs'
|
||||
import path from 'path'
|
||||
import { getAuthPath } from '../../../shared/src/constants'
|
||||
import { getAuthPath } from '../config'
|
||||
import { logger } from '../utils/logger'
|
||||
import { AuthCredentialsSchema } from '../../../shared/src/schemas/auth'
|
||||
import type { z } from 'zod'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { promises as fs } from 'fs'
|
||||
import path from 'path'
|
||||
import { logger } from '../utils/logger'
|
||||
import { getWorkspacePath, getReposPath } from '../../../shared/src/constants'
|
||||
import { getReposPath } from '../config'
|
||||
|
||||
export async function readFileContent(filePath: string): Promise<string> {
|
||||
try {
|
||||
|
||||
@@ -11,8 +11,7 @@ import {
|
||||
getFileStats,
|
||||
listDirectory
|
||||
} from './file-operations'
|
||||
import { FILE_LIMITS, ALLOWED_MIME_TYPES } from '../../../shared/src/constants'
|
||||
import { getReposPath } from '../../../shared/src/constants'
|
||||
import { FILE_LIMITS, ALLOWED_MIME_TYPES, getReposPath } from '../config'
|
||||
|
||||
const SHARED_WORKSPACE_BASE = getReposPath()
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { spawn } from 'child_process'
|
||||
import { logger } from '../utils/logger'
|
||||
import { getWorkspacePath } from '../../../shared/src/constants'
|
||||
import { execSync } from 'child_process'
|
||||
import { ENV } from '../config'
|
||||
import { spawn, execSync } from 'child_process'
|
||||
import path from 'path'
|
||||
import { logger } from '../utils/logger'
|
||||
import { getWorkspacePath, ENV } from '../config'
|
||||
|
||||
const OPENCODE_SERVER_PORT = ENV.OPENCODE_SERVER_PORT
|
||||
const OPENCODE_SERVER_PORT = ENV.OPENCODE.PORT
|
||||
const OPENCODE_SERVER_DIRECTORY = getWorkspacePath()
|
||||
|
||||
class OpenCodeServerManager {
|
||||
@@ -29,7 +27,7 @@ class OpenCodeServerManager {
|
||||
return
|
||||
}
|
||||
|
||||
const isDevelopment = process.env.NODE_ENV !== 'production'
|
||||
const isDevelopment = ENV.SERVER.NODE_ENV !== 'production'
|
||||
|
||||
const existingProcesses = await this.findProcessesByPort(OPENCODE_SERVER_PORT)
|
||||
if (existingProcesses.length > 0) {
|
||||
@@ -66,29 +64,25 @@ class OpenCodeServerManager {
|
||||
}
|
||||
}
|
||||
|
||||
logger.info(`Starting OpenCode server on port ${OPENCODE_SERVER_PORT} (${isDevelopment ? 'development' : 'production'} mode)`)
|
||||
logger.info(`OpenCode server working directory: ${OPENCODE_SERVER_DIRECTORY}`)
|
||||
logger.info(`OpenCode will use ?directory= parameter for session isolation`)
|
||||
|
||||
const hostname = isDevelopment ? '0.0.0.0' : '127.0.0.1'
|
||||
|
||||
this.serverProcess = spawn(
|
||||
'opencode',
|
||||
['serve', '--port', OPENCODE_SERVER_PORT.toString(), '--hostname', hostname],
|
||||
['serve', '--port', OPENCODE_SERVER_PORT.toString(), '--hostname', '127.0.0.1'],
|
||||
{
|
||||
cwd: OPENCODE_SERVER_DIRECTORY,
|
||||
detached: !isDevelopment,
|
||||
stdio: isDevelopment ? 'inherit' : 'ignore',
|
||||
env: {
|
||||
...process.env,
|
||||
XDG_DATA_HOME: path.join(OPENCODE_SERVER_DIRECTORY, '.opencode/state')
|
||||
XDG_DATA_HOME: path.join(OPENCODE_SERVER_DIRECTORY, '.opencode/state'),
|
||||
OPENCODE_CONFIG: path.join(OPENCODE_SERVER_DIRECTORY, '.config/opencode/opencode.json')
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
if (!isDevelopment) {
|
||||
this.serverProcess.unref()
|
||||
}
|
||||
this.serverPid = this.serverProcess.pid
|
||||
|
||||
logger.info(`OpenCode server started with PID ${this.serverPid}`)
|
||||
@@ -131,7 +125,7 @@ class OpenCodeServerManager {
|
||||
|
||||
async checkHealth(): Promise<boolean> {
|
||||
try {
|
||||
const response = await fetch(`http://localhost:${OPENCODE_SERVER_PORT}/doc`, {
|
||||
const response = await fetch(`http://127.0.0.1:${OPENCODE_SERVER_PORT}/doc`, {
|
||||
signal: AbortSignal.timeout(3000)
|
||||
})
|
||||
return response.ok
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { logger } from '../utils/logger'
|
||||
import { ENV } from '../config'
|
||||
|
||||
const OPENCODE_SERVER_URL = `http://localhost:${ENV.OPENCODE_SERVER_PORT}`
|
||||
const OPENCODE_SERVER_URL = `http://127.0.0.1:${ENV.OPENCODE.PORT}`
|
||||
|
||||
export async function proxyRequest(request: Request) {
|
||||
const url = new URL(request.url)
|
||||
@@ -44,4 +44,4 @@ export async function proxyRequest(request: Request) {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import type { Database } from 'bun:sqlite'
|
||||
import type { Repo, CreateRepoInput } from '../types/repo'
|
||||
import { logger } from '../utils/logger'
|
||||
import { SettingsService } from './settings'
|
||||
import { getReposPath } from '../../../shared/src/constants'
|
||||
import { getReposPath } from '../config'
|
||||
import path from 'path'
|
||||
|
||||
export async function cloneRepo(
|
||||
|
||||
Reference in new issue
Block a user