chore: update Docker config, dev-proxy, and HTML preview components

This commit is contained in:
Chris Scott committed 2026-06-21 17:17:33 -04:00
1 parent 9afd5f04d5
commit 088b1d7b18
9 files changed
+53 -87

No files matched your search

+1 -1
View File
@@ -112,7 +112,7 @@ RUN chmod +x /docker-entrypoint.sh
RUN mkdir -p /workspace /app/data /home/node/.cache /home/node/.opencode && \
chown -R node:node /workspace /app/data /home/node
EXPOSE 5003 5100 5101 5102 5103
EXPOSE 5003 3055
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
CMD curl -f http://localhost:5003/api/health || exit 1
+1 -1
View File
@@ -49,7 +49,6 @@ async function handleProxyRequest(c: Context, db: Database): Promise<Response> {
return c.json({ error: 'Invalid repoId' }, 400)
}
const config = getDevServerConfig(db, repoId)
const port = getDevServerPort(db)
if (isWebSocketUpgrade((key: string) => c.req.header(key))) {
@@ -91,6 +90,7 @@ async function handleProxyRequest(c: Context, db: Database): Promise<Response> {
const contentType = upstreamResponse.headers.get('content-type') ?? ''
if (contentType.includes('text/html')) {
const config = getDevServerConfig(db, repoId)
const text = await upstreamResponse.text()
const basePath = `${DEV_PROXY_PREFIX}/${repoId}/`
const modified = config.injectBase ? injectBaseTag(text, basePath) : rewriteDevProxyHtmlPaths(text, basePath)
@@ -1,6 +1,6 @@
export const DEV_PROXY_PREFIX = '/api/dev-proxy'
export const HOP_BY_HOP_HEADERS = new Set([
const HOP_BY_HOP_HEADERS = new Set([
'connection',
'keep-alive',
'proxy-authenticate',
@@ -166,8 +166,7 @@ function rewriteSrcSetCandidate(candidate: string, basePath: string): string {
function toDevProxyPath(path: string, basePath: string): string {
const normalizedBasePath = basePath.endsWith('/') ? basePath.slice(0, -1) : basePath
const escapedBasePath = escapeRegExp(normalizedBasePath)
if (new RegExp(`^${escapedBasePath}(?:/|$)`).test(path)) return path
if (path === normalizedBasePath || path.startsWith(`${normalizedBasePath}/`)) return path
return `${normalizedBasePath}${path}`
}
@@ -177,6 +176,3 @@ function isBaseTagAttribute(html: string, attributeOffset: number): boolean {
return /^<\s*base\b/i.test(html.slice(tagStart, attributeOffset))
}
function escapeRegExp(value: string): string {
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
}
+1 -4
View File
@@ -8,10 +8,7 @@ services:
container_name: opencode-manager
ports:
- "5003:5003"
- "5100:5100"
- "5101:5101"
- "5102:5102"
- "5103:5103"
- "3055:3055"
environment:
- NODE_ENV=${NODE_ENV:-production}
- HOST=0.0.0.0
+11 -15
View File
@@ -38,10 +38,7 @@ services:
container_name: opencode-manager
ports:
- "5003:5003"
- "5100:5100"
- "5101:5101"
- "5102:5102"
- "5103:5103"
- "3055:3055"
environment:
- NODE_ENV=${NODE_ENV:-production}
- HOST=0.0.0.0
@@ -146,19 +143,18 @@ ports:
- "8080:5003" # Access at localhost:8080
```
### Dev Server Ports
### Dev Server Port
Ports 5100-5103 are exposed for running dev servers inside repositories:
The preview proxy reaches a repository's dev server through the main `5003` port at `/api/dev-proxy/<repoId>/`, so the dev server only needs to listen on a single port inside the container. That port defaults to `3055` and is configurable in **Settings** (`devServerPort`); agents receive it as the `$OCM_DEV_SERVER_PORT` environment variable.
Exposing the port to the host is optional — the preview works entirely through `5003`. Map it only if you also want to hit the dev server directly:
```yaml
ports:
- "5100:5100"
- "5101:5101"
- "5102:5102"
- "5103:5103"
- "3055:3055"
```
Configure your dev server to use one of these ports:
Run your dev server on `$OCM_DEV_SERVER_PORT` and bind to `0.0.0.0`:
=== "Vite"
@@ -166,7 +162,7 @@ Configure your dev server to use one of these ports:
// vite.config.ts
export default {
server: {
port: 5100,
port: Number(process.env.OCM_DEV_SERVER_PORT) || 3055,
host: '0.0.0.0'
}
}
@@ -175,13 +171,13 @@ Configure your dev server to use one of these ports:
=== "Next.js"
```bash
next dev -p 5100 -H 0.0.0.0
next dev -p $OCM_DEV_SERVER_PORT -H 0.0.0.0
```
=== "Express"
```javascript
app.listen(5100, '0.0.0.0')
app.listen(process.env.OCM_DEV_SERVER_PORT || 3055, '0.0.0.0')
```
## Volume Mounts
@@ -372,7 +368,7 @@ The container creates a default `AGENTS.md` file at `/workspace/.config/opencode
Instructions for AI agents working in the container:
- Reserved ports information
- Available dev server ports
- Dev server port (`$OCM_DEV_SERVER_PORT`, default 3055)
- Docker-specific guidelines
### Editing
@@ -154,27 +154,27 @@ export const FileBrowser = forwardRef<FileBrowserHandle, FileBrowserProps>(funct
const uploadCancelledRef = useRef(false)
const isMobile = useMobile()
const openMobilePreview = useCallback((file: FileInfo) => {
if (isHtmlFileInfo(file)) {
setHtmlArtifact(createHtmlArtifact({ source: 'file', path: file.path, title: file.name }))
setIsPreviewModalOpen(false)
} else {
setHtmlArtifact(null)
setIsPreviewModalOpen(true)
}
onPreviewStateChange?.(true)
}, [onPreviewStateChange])
const { data: initialFileData, error: initialFileError } = useFile(initialSelectedFile)
useEffect(() => {
if (initialFileData) {
setSelectedFile(initialFileData)
if (isMobile) {
if (isHtmlFileInfo(initialFileData)) {
setHtmlArtifact(createHtmlArtifact({
source: 'file',
path: initialFileData.path,
title: initialFileData.name,
}))
setIsPreviewModalOpen(false)
} else {
setHtmlArtifact(null)
setIsPreviewModalOpen(true)
}
onPreviewStateChange?.(true)
openMobilePreview(initialFileData)
}
}
}, [initialFileData, isMobile, onPreviewStateChange])
}, [initialFileData, isMobile, openMobilePreview])
useEffect(() => {
if (initialFileError) {
@@ -280,18 +280,7 @@ useEffect(() => {
// On mobile, open preview in modal
if (isMobile) {
if (isHtmlFileInfo(fullFileData)) {
setHtmlArtifact(createHtmlArtifact({
source: 'file',
path: fullFileData.path,
title: fullFileData.name,
}))
setIsPreviewModalOpen(false)
} else {
setHtmlArtifact(null)
setIsPreviewModalOpen(true)
}
onPreviewStateChange?.(true)
openMobilePreview(fullFileData)
}
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to load file')
@@ -299,23 +288,15 @@ useEffect(() => {
} finally {
setLoading(false)
}
}, [onFileSelect, isMobile, onPreviewStateChange])
}, [onFileSelect, isMobile, openMobilePreview])
const handleCloseModal = useCallback(() => {
const handleClosePreview = useCallback(() => {
setIsPreviewModalOpen(false)
setHtmlArtifact(null)
setSelectedFile(null)
onPreviewStateChange?.(false)
}, [onPreviewStateChange])
const handleCloseHtmlArtifact = useCallback(() => {
setHtmlArtifact(null)
setSelectedFile(null)
onPreviewStateChange?.(false)
}, [onPreviewStateChange])
const handleToggleHtmlArtifactFullscreen = useCallback(() => {}, [])
const handleDirectoryClick = (path: string) => {
loadFiles(path)
}
@@ -513,13 +494,13 @@ useEffect(() => {
const handleEscape = (e: KeyboardEvent) => {
if (e.key === 'Escape') {
handleCloseModal()
handleClosePreview()
}
}
document.addEventListener('keydown', handleEscape)
return () => document.removeEventListener('keydown', handleEscape)
}, [isPreviewModalOpen, handleCloseModal])
}, [isPreviewModalOpen, handleClosePreview])
const showNavigateUp = allowNavigateAboveBase && normalizePath(currentPath) !== '..'
? true
@@ -592,6 +573,15 @@ useEffect(() => {
</Dialog>
)
const htmlArtifactPanel = isMobile && htmlArtifact && (
<HtmlArtifactPanel
artifact={htmlArtifact}
isFullscreen={true}
isMobile={true}
onClose={handleClosePreview}
/>
)
if (embedded) {
return (
<div
@@ -678,20 +668,12 @@ useEffect(() => {
{/* Mobile: File Preview Modal */}
<MobileFilePreviewModal
isOpen={isMobile && isPreviewModalOpen}
onClose={handleCloseModal}
onClose={handleClosePreview}
file={selectedFile}
showFilePreviewHeader={true}
/>
{isMobile && htmlArtifact && (
<HtmlArtifactPanel
artifact={htmlArtifact}
isFullscreen={true}
isMobile={true}
onClose={handleCloseHtmlArtifact}
onToggleFullscreen={handleToggleHtmlArtifactFullscreen}
/>
)}
{htmlArtifactPanel}
</div>
)
}
@@ -790,19 +772,11 @@ useEffect(() => {
{/* Mobile: File Preview Modal */}
<MobileFilePreviewModal
isOpen={isMobile && isPreviewModalOpen}
onClose={handleCloseModal}
onClose={handleClosePreview}
file={selectedFile}
/>
{isMobile && htmlArtifact && (
<HtmlArtifactPanel
artifact={htmlArtifact}
isFullscreen={true}
isMobile={true}
onClose={handleCloseHtmlArtifact}
onToggleFullscreen={handleToggleHtmlArtifactFullscreen}
/>
)}
{htmlArtifactPanel}
{uploadDialog}
</div>
@@ -14,7 +14,7 @@ interface HtmlArtifactPanelProps {
isFullscreen: boolean
isMobile: boolean
onClose: () => void
onToggleFullscreen: () => void
onToggleFullscreen?: () => void
}
export function HtmlArtifactPanel({
@@ -1,3 +1,4 @@
import { useMemo } from 'react'
import { cn } from '@/lib/utils'
import { normalizeHtmlPreviewDocument } from '@/lib/htmlArtifacts'
@@ -11,7 +12,7 @@ interface HtmlPreviewFrameProps {
export function HtmlPreviewFrame({ title, src, srcDoc, className, sandbox }: HtmlPreviewFrameProps) {
const resolvedSandbox = sandbox ?? (src ? 'allow-scripts allow-same-origin' : 'allow-scripts')
const normalizedSrcDoc = srcDoc ? normalizeHtmlPreviewDocument(srcDoc) : undefined
const normalizedSrcDoc = useMemo(() => (srcDoc ? normalizeHtmlPreviewDocument(srcDoc) : undefined), [srcDoc])
return (
<iframe
title={title}
+3 -1
View File
@@ -171,7 +171,9 @@ function CodeBlock({ children, className, onHtmlArtifactOpen, ...props }: CodeBl
const codeContent = rawCodeContent.trim()
const childArray = React.Children.toArray(children)
const codeElement = childArray.find((child): child is React.ReactElement => React.isValidElement(child))
const codeElement = childArray.find(
(child): child is React.ReactElement<{ className?: string }> => React.isValidElement(child)
)
const codeClassName = codeElement?.props?.className
const isHtmlCode = typeof codeClassName === 'string' && (codeClassName.includes('language-html') || codeClassName.includes('language-htm'))