MCPcopy
hub / github.com/anomalyco/opencode / serverFetch

Function serverFetch

packages/opencode/test/server/httpapi-sdk.test.ts:84–105  ·  view source on GitHub ↗
(
  serverPath: ServerPath,
  input?: { password?: string; username?: string; onRequest?: (request: Request) => void },
)

Source from the content-addressed store, hash-verified

82}
83
84function serverFetch(
85 serverPath: ServerPath,
86 input?: { password?: string; username?: string; onRequest?: (request: Request) => void },
87) {
88 return HttpServer.HttpServer.use((server) =>
89 Effect.sync(() => {
90 void serverPath
91 Flag.OPENCODE_SERVER_PASSWORD = input?.password
92 Flag.OPENCODE_SERVER_USERNAME = input?.username
93 const baseUrl = HttpServer.formatAddress(server.address)
94 return Object.assign(
95 async (request: RequestInfo | URL, init?: RequestInit) => {
96 const source = request instanceof Request ? request : new Request(request, init)
97 input?.onRequest?.(source)
98 const url = new URL(source.url)
99 return globalThis.fetch(new Request(new URL(`${url.pathname}${url.search}`, baseUrl), source))
100 },
101 { preconnect: globalThis.fetch.preconnect },
102 ) satisfies typeof globalThis.fetch
103 }),
104 )
105}
106
107function authorization(username: string, password: string) {
108 return `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`

Callers 2

clientFunction · 0.85

Calls 3

syncMethod · 0.80
fetchMethod · 0.80
useMethod · 0.45

Tested by

no test coverage detected