mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-18 10:07:58 +00:00
This reverts: -28b03595bresearch: delete Hono backend (do not merge) (#25667) -b24a4e897chore(server): clean up post-Hono-deletion scar tissue (#26542) v1.14.42 broke startup for users with plugins that depend on the Hono wire format (most visibly opencode-gemini-auth, see #26546). Restoring Hono as the default backend on stable channels while we investigate the actual plugin compatibility story. OPENCODE_EXPERIMENTAL_HTTPAPI flag and dual-backend selection come back. Stable installs default to Hono; dev/beta default to HTTP API. Conflict resolution: took the pre-deletion side for control-plane schemas and the seven test files where post-deletion follow-up PRs had also touched the conflicting lines. The HTTP API code added since the deletion (compression, cors-vary, fence, lifecycle log, account error mapping, etc.) is preserved as-is — those still apply on the HTTP API path for users on dev/beta channels.
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { NodeHttpServer } from "@effect/platform-node"
|
|
import { Effect, Layer } from "effect"
|
|
import { createServer } from "node:http"
|
|
import type { Opts } from "./adapter"
|
|
import { Service } from "./httpapi-server"
|
|
|
|
export { Service }
|
|
|
|
export const name = "node-http-server"
|
|
|
|
export const layer = (opts: Opts) => {
|
|
const server = createServer()
|
|
const serverRef = { closeStarted: false, forceStop: false }
|
|
const close = server.close.bind(server)
|
|
// Keep shutdown owned by NodeHttpServer, but honor listener.stop(true) by
|
|
// force-closing active HTTP sockets when its finalizer calls server.close().
|
|
server.close = ((callback?: Parameters<typeof server.close>[0]) => {
|
|
serverRef.closeStarted = true
|
|
const result = close(callback)
|
|
if (serverRef.forceStop) server.closeAllConnections()
|
|
return result
|
|
}) as typeof server.close
|
|
return Layer.mergeAll(
|
|
NodeHttpServer.layer(() => server, { port: opts.port, host: opts.hostname, gracefulShutdownTimeout: "1 second" }),
|
|
Layer.succeed(Service)(
|
|
Service.of({
|
|
closeAll: Effect.sync(() => {
|
|
serverRef.forceStop = true
|
|
if (serverRef.closeStarted) server.closeAllConnections()
|
|
}),
|
|
}),
|
|
),
|
|
)
|
|
}
|