mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-05 07:00:00 +00:00
serve: expose socket listener url
This commit is contained in:
parent
41f0f7d407
commit
12c19d627d
2 changed files with 10 additions and 0 deletions
|
|
@ -30,6 +30,7 @@ export type TcpListener = {
|
|||
export type SocketListener = {
|
||||
type: "socket"
|
||||
socket: string
|
||||
url: URL
|
||||
stop: (close?: boolean) => Promise<void>
|
||||
}
|
||||
|
||||
|
|
@ -101,6 +102,7 @@ export async function listen(opts: ListenOptions): Promise<Listener> {
|
|||
return {
|
||||
type: "socket" as const,
|
||||
socket: listener.socket,
|
||||
url: listener.url,
|
||||
stop,
|
||||
}
|
||||
}
|
||||
|
|
@ -117,9 +119,12 @@ const listenEffect: (opts: ListenOptions) => Effect.Effect<EffectListener, unkno
|
|||
function* (opts: ListenOptions) {
|
||||
const state = yield* startWithPortFallback(opts)
|
||||
if (opts.type === "socket") {
|
||||
const listenerUrl = makeSocketURL(opts.socket)
|
||||
|
||||
return {
|
||||
type: "socket" as const,
|
||||
socket: opts.socket,
|
||||
url: listenerUrl,
|
||||
stop: yield* makeStop(state, Effect.void),
|
||||
}
|
||||
}
|
||||
|
|
@ -195,6 +200,10 @@ function makeURL(hostname: string, port?: number) {
|
|||
return result
|
||||
}
|
||||
|
||||
function makeSocketURL(socket: string) {
|
||||
return new URL(`socket:${encodeURIComponent(socket)}`)
|
||||
}
|
||||
|
||||
function setupMdns(opts: TcpListenOptions, port: number, scope: Scope.Scope) {
|
||||
return Effect.gen(function* () {
|
||||
const publish =
|
||||
|
|
|
|||
|
|
@ -297,6 +297,7 @@ describe("HttpApi Server.listen", () => {
|
|||
try {
|
||||
expect(listener.type).toBe("socket")
|
||||
expect(listener.socket).toBe(socket)
|
||||
expect(listener.url.href).toBe(`socket:${encodeURIComponent(socket)}`)
|
||||
|
||||
const response = await requestSocketRoot(socket)
|
||||
expect(response.statusCode).toBe(200)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue