mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +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
+36
-9
@@ -6,7 +6,7 @@ import { initializeDatabase } from './db/schema'
|
||||
import { createRepoRoutes } from './routes/repos'
|
||||
import { createSettingsRoutes } from './routes/settings'
|
||||
import { createHealthRoutes } from './routes/health'
|
||||
import { createSessionRoutes } from './routes/sessions'
|
||||
|
||||
import { createFileRoutes } from './routes/files'
|
||||
import { createProvidersRoutes } from './routes/providers'
|
||||
import { ensureDirectoryExists } from './services/file-operations'
|
||||
@@ -14,12 +14,16 @@ import { opencodeServerManager } from './services/opencode-single-server'
|
||||
import { cleanupOrphanedDirectories } from './services/repo'
|
||||
import { proxyRequest } from './services/proxy'
|
||||
import { logger } from './utils/logger'
|
||||
import { ENV } from './config'
|
||||
import { getWorkspacePath, getReposPath, getConfigPath } from '../../shared/src/constants'
|
||||
import {
|
||||
getWorkspacePath,
|
||||
getReposPath,
|
||||
getConfigPath,
|
||||
getDatabasePath,
|
||||
ENV
|
||||
} from './config'
|
||||
|
||||
await import('dotenv/config')
|
||||
|
||||
const { PORT, HOST, DATABASE_PATH: DB_PATH } = ENV
|
||||
const { PORT, HOST } = ENV.SERVER
|
||||
const DB_PATH = getDatabasePath()
|
||||
|
||||
const app = new Hono()
|
||||
|
||||
@@ -49,7 +53,6 @@ try {
|
||||
app.route('/api/repos', createRepoRoutes(db))
|
||||
app.route('/api/settings', createSettingsRoutes(db))
|
||||
app.route('/api/health', createHealthRoutes(db))
|
||||
app.route('/api/sessions', createSessionRoutes())
|
||||
app.route('/api/files', createFileRoutes(db))
|
||||
app.route('/api/providers', createProvidersRoutes())
|
||||
|
||||
@@ -58,7 +61,7 @@ app.all('/api/opencode/*', async (c) => {
|
||||
return proxyRequest(request)
|
||||
})
|
||||
|
||||
const isProduction = process.env.NODE_ENV === 'production'
|
||||
const isProduction = ENV.SERVER.NODE_ENV === 'production'
|
||||
|
||||
if (isProduction) {
|
||||
app.use('/*', async (c, next) => {
|
||||
@@ -87,6 +90,30 @@ if (isProduction) {
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/api/network-info', async (c) => {
|
||||
const os = await import('os')
|
||||
const interfaces = os.networkInterfaces()
|
||||
const ips = Object.values(interfaces)
|
||||
.flat()
|
||||
.filter(info => info && !info.internal && info.family === 'IPv4')
|
||||
.map(info => info!.address)
|
||||
|
||||
const requestHost = c.req.header('host') || `localhost:${PORT}`
|
||||
const protocol = c.req.header('x-forwarded-proto') || 'http'
|
||||
|
||||
return c.json({
|
||||
host: HOST,
|
||||
port: PORT,
|
||||
requestHost,
|
||||
protocol,
|
||||
availableIps: ips,
|
||||
apiUrls: [
|
||||
`${protocol}://localhost:${PORT}`,
|
||||
...ips.map(ip => `${protocol}://${ip}:${PORT}`)
|
||||
]
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
let isShuttingDown = false
|
||||
@@ -114,4 +141,4 @@ serve({
|
||||
hostname: HOST,
|
||||
})
|
||||
|
||||
logger.info(`🚀 OpenCode WebUI API running on http://${HOST}:${PORT}`)
|
||||
logger.info(`🚀 OpenCode WebUI API running on http://${HOST}:${PORT}`)
|
||||
Reference in new issue
Block a user