host.http
Listen for HTTP requests on a client and handle them in the cloud runtime.
The HTTP server interface listens on the selected client and handles requests in the cloud JavaScript environment, streaming request and response bodies.
Here, host is a selected RemoteHost; see host discovery to obtain one. The module overview covers permissions and shared errors.
host.http.serve(options)
Function: listens for plain HTTP/1.1 on the client and forwards requests to a cloud handler. Both body directions stream on demand. Requires http_server.enabled.
| Parameter | Type | Required | Description |
|---|---|---|---|
options | HttpServerOptions | Yes | Server configuration |
options.hostname | string | No | Defaults to 127.0.0.1 |
options.port | number | No | Defaults to 8080; integer 0–65535, with 0 allocating a free port |
options.fetch | (request: Request) => Response | Promise<Response> | Yes | Handler executed in the cloud |
Return value: Promise<HttpServer>. The handler receives the original method, including TRACE / TRACK; request.signal reports client disconnection. A thrown or rejected handler produces HTTP 500.
This does not publish a task URL. For public serving, use the default-exported HTTP entry.
HttpServer
| Property / method | Function and parameters | Type / return value |
|---|---|---|
server.addr | Actual listening address, read-only | Readonly<TcpAddress> |
server.finished | Completes after listener, accepted requests, and response bodies finish; rejects on transport or cleanup failure | Promise<void> |
server.shutdown() | No arguments; stop accepting and drain responses; safe to repeat | Promise<void> |
Address objects contain hostname: string and port: number, as with TCP addresses.
Do not await a server's own shutdown() inside a request being handled: it would wait for itself. shutdown() and finished report the same first transport or cleanup error.
See remote.d.ts for type declarations.
