Interface: Server
An HTTP server instance.
Extends
AsyncDisposable
Properties
port
readonlyport:number
The port the server is listening on.
Methods
close()
close():
Promise<void>
Stop accepting new connections and close the server. The returned promise resolves once the listening socket has been fully torn down. Idempotent; subsequent calls return the same promise.
Aliased as Symbol.asyncDispose, so
await using server = tjs.serve(...) closes it automatically at
scope exit.
Returns
Promise<void>
upgrade()
upgrade(
request,options?):boolean
Upgrade an HTTP request to a WebSocket connection. Must be called synchronously inside the fetch handler.
Parameters
request
Request
The incoming request with an Upgrade: websocket header.
options?
Options for the WebSocket connection.
Returns
boolean
true if the upgrade was successful, false otherwise.