Skip to content

Commit cfdd12e

Browse files
committed
Serve static files if available instead of proxying
1 parent d438f6e commit cfdd12e

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

packages/opencode/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ research
22
dist
33
gen
44
app.log
5+
static

packages/opencode/src/installation/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BusEvent } from "@/bus/bus-event"
22
import { Bus } from "@/bus"
33
import path from "path"
4+
import fs from "fs"
45
import { $ } from "bun"
56
import z from "zod"
67
import { NamedError } from "@opencode-ai/util/error"
@@ -62,6 +63,11 @@ export namespace Installation {
6263
return CHANNEL === "local"
6364
}
6465

66+
export function isBundled() {
67+
const staticPath = path.join(path.dirname(process.execPath), "static")
68+
return fs.existsSync(staticPath)
69+
}
70+
6571
export async function method() {
6672
const exec = process.execPath.toLowerCase()
6773

packages/opencode/src/server/server.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ import { TuiEvent } from "@/cli/cmd/tui/event"
4545
import { Snapshot } from "@/snapshot"
4646
import { SessionSummary } from "@/session/summary"
4747
import { SessionStatus } from "@/session/status"
48-
import { upgradeWebSocket, websocket } from "hono/bun"
48+
import { upgradeWebSocket, websocket, serveStatic } from "hono/bun"
4949
import { errors } from "./error"
5050
import { Pty } from "@/pty"
5151
import { Installation } from "@/installation"
52+
import fs from "fs"
53+
import path from "path"
5254

5355
// @ts-ignore This global is needed to prevent ai-sdk from logging warnings to stdout https://github.com/vercel/ai/blob/2dc67e0ef538307f21368db32d5a12345d98831b/packages/ai/src/logger/log-warnings.ts#L85
5456
globalThis.AI_SDK_LOG_WARNINGS = false
@@ -2580,6 +2582,14 @@ export namespace Server {
25802582
},
25812583
)
25822584
.all("/*", async (c) => {
2585+
if (Installation.isBundled()) {
2586+
const res = await serveStatic({
2587+
root: path.relative(process.cwd(), path.join(path.dirname(process.execPath), "static")),
2588+
rewriteRequestPath: (path) => (path === "/" ? "/index.html" : path),
2589+
})(c, async () => {})
2590+
if (res) return res
2591+
}
2592+
25832593
const desktopHost = Installation.isLocal()
25842594
? process.env.OPENCODE_DESKTOP_URL || "http://localhost:3000"
25852595
: process.env.SHUVCODE_DESKTOP_URL || "https://desktop.shuv.ai"

0 commit comments

Comments
 (0)