mirror of
https://github.com/sst/opencode.git
synced 2025-08-25 15:34:06 +00:00
Add Unix domain socket support for server binding
- Add --unix option to serve and tui commands - Update Server.listen() to accept unix socket path - Unix socket overrides port/hostname when specified - Enables parallel testing with isolated instances Fixes issue where multiple opencode instances needed unique socket addresses for parallel testing. Unix sockets provide deterministic addresses without port conflicts.
This commit is contained in:
parent
6018364164
commit
bde754b25f
3 changed files with 27 additions and 6 deletions
|
@ -18,6 +18,10 @@ export const ServeCommand = cmd({
|
||||||
type: "string",
|
type: "string",
|
||||||
describe: "hostname to listen on",
|
describe: "hostname to listen on",
|
||||||
default: "127.0.0.1",
|
default: "127.0.0.1",
|
||||||
|
})
|
||||||
|
.option("unix", {
|
||||||
|
type: "string",
|
||||||
|
describe: "unix socket path to bind to (overrides port/hostname)",
|
||||||
}),
|
}),
|
||||||
describe: "starts a headless opencode server",
|
describe: "starts a headless opencode server",
|
||||||
handler: async (args) => {
|
handler: async (args) => {
|
||||||
|
@ -34,9 +38,14 @@ export const ServeCommand = cmd({
|
||||||
const server = Server.listen({
|
const server = Server.listen({
|
||||||
port,
|
port,
|
||||||
hostname,
|
hostname,
|
||||||
|
unix: args.unix,
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(`opencode server listening on http://${server.hostname}:${server.port}`)
|
if (args.unix) {
|
||||||
|
console.log(`opencode server listening on unix socket: ${args.unix}`)
|
||||||
|
} else {
|
||||||
|
console.log(`opencode server listening on http://${server.hostname}:${server.port}`)
|
||||||
|
}
|
||||||
|
|
||||||
await new Promise(() => {})
|
await new Promise(() => {})
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,10 @@ export const TuiCommand = cmd({
|
||||||
type: "string",
|
type: "string",
|
||||||
describe: "hostname to listen on",
|
describe: "hostname to listen on",
|
||||||
default: "127.0.0.1",
|
default: "127.0.0.1",
|
||||||
|
})
|
||||||
|
.option("unix", {
|
||||||
|
type: "string",
|
||||||
|
describe: "unix socket path to bind to (overrides port/hostname)",
|
||||||
}),
|
}),
|
||||||
handler: async (args) => {
|
handler: async (args) => {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -108,6 +112,7 @@ export const TuiCommand = cmd({
|
||||||
const server = Server.listen({
|
const server = Server.listen({
|
||||||
port: args.port,
|
port: args.port,
|
||||||
hostname: args.hostname,
|
hostname: args.hostname,
|
||||||
|
unix: args.unix,
|
||||||
})
|
})
|
||||||
|
|
||||||
let cmd = ["go", "run", "./main.go"]
|
let cmd = ["go", "run", "./main.go"]
|
||||||
|
|
|
@ -1235,13 +1235,20 @@ export namespace Server {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
export function listen(opts: { port: number; hostname: string }) {
|
export function listen(opts: { port?: number; hostname?: string; unix?: string }) {
|
||||||
const server = Bun.serve({
|
const serverOpts: any = {
|
||||||
port: opts.port,
|
|
||||||
hostname: opts.hostname,
|
|
||||||
idleTimeout: 0,
|
idleTimeout: 0,
|
||||||
fetch: app().fetch,
|
fetch: app().fetch,
|
||||||
})
|
}
|
||||||
|
|
||||||
|
if (opts.unix) {
|
||||||
|
serverOpts.unix = opts.unix
|
||||||
|
} else {
|
||||||
|
serverOpts.port = opts.port || 0
|
||||||
|
serverOpts.hostname = opts.hostname || "127.0.0.1"
|
||||||
|
}
|
||||||
|
|
||||||
|
const server = Bun.serve(serverOpts)
|
||||||
return server
|
return server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue