Skip to content

Commit 89d6f60

Browse files
committed
refactor(server): extract createApp function for server initialization
- Replace Server.App() with Server.Default() for internal server access - Extract server app creation into Server.createApp(opts) for testability - Move CORS whitelist from module-level variable to function parameter - Update all tests to use Server.Default() instead of Server.App()
1 parent ee18c99 commit 89d6f60

6 files changed

Lines changed: 461 additions & 472 deletions

File tree

packages/opencode/src/cli/cmd/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ export const RunCommand = cmd({
667667
await bootstrap(process.cwd(), async () => {
668668
const fetchFn = (async (input: RequestInfo | URL, init?: RequestInit) => {
669669
const request = new Request(input, init)
670-
return Server.App().fetch(request)
670+
return Server.Default().fetch(request)
671671
}) as typeof globalThis.fetch
672672
const sdk = createOpencodeClient({ baseUrl: "http://opencode.internal", fetch: fetchFn })
673673
await execute(sdk)

packages/opencode/src/cli/cmd/tui/worker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const startEventStream = (input: { directory: string; workspaceID?: string }) =>
5454
const request = new Request(input, init)
5555
const auth = getAuthorizationHeader()
5656
if (auth) request.headers.set("Authorization", auth)
57-
return Server.App().fetch(request)
57+
return Server.Default().fetch(request)
5858
}) as typeof globalThis.fetch
5959

6060
const sdk = createOpencodeClient({
@@ -110,7 +110,7 @@ export const rpc = {
110110
headers,
111111
body: input.body,
112112
})
113-
const response = await Server.App().fetch(request)
113+
const response = await Server.Default().fetch(request)
114114
const body = await response.text()
115115
return {
116116
status: response.status,

packages/opencode/src/plugin/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ export namespace Plugin {
2525
const client = createOpencodeClient({
2626
baseUrl: "http://localhost:4096",
2727
directory: Instance.directory,
28-
// @ts-ignore - fetch type incompatibility
29-
fetch: async (...args) => Server.App().fetch(...args),
28+
fetch: async (...args) => Server.Default().fetch(...args),
3029
})
3130
const config = await Config.get()
3231
const hooks: Hooks[] = []
@@ -35,7 +34,9 @@ export namespace Plugin {
3534
project: Instance.project,
3635
worktree: Instance.worktree,
3736
directory: Instance.directory,
38-
serverUrl: Server.url(),
37+
get serverUrl(): URL {
38+
throw new Error("Server URL is no longer supported in plugins")
39+
},
3940
$: Bun.$,
4041
}
4142

0 commit comments

Comments
 (0)