serve

View as MarkdownOpen in Claude

Start the HTTP server that serves the SWML document. This is a Python-compat alias for run() and forwards all arguments unchanged. Use either name interchangeably — pick serve() when porting code from the Python SDK.

Returns immediately when SWAIG_CLI_MODE=true is set, so the CLI testing tool can load the service without opening a port.

serve() (and run()) start a @hono/node-server instance that runs until explicitly stopped. For embedding into an existing application, use asRouter() to get a mountable Hono sub-app instead.

Parameters

host
string

Hostname to bind to. Defaults to the host passed to the constructor, or "0.0.0.0".

port
number

Port number to listen on. Defaults to the port passed to the constructor, which itself falls back to the PORT environment variable or 3000.

opts
object

Optional SSL/TLS overrides. Each field falls back to the matching value on the service instance.

opts.sslCert
string

Path to the SSL certificate file.

opts.sslKey
string

Path to the SSL private key file.

opts.sslEnabled
boolean

Override whether SSL/HTTPS is enabled for this run.

opts.domain
string

Domain name associated with the SSL certificate.

Returns

Promise<void> — resolves once the listener is bound.

Example

1import { SWMLService } from '@signalwire/sdk';
2
3const service = new SWMLService({ name: 'my-service', route: '/swml' });
4service.addVerb('answer', {});
5service.addVerb('play', { url: 'https://example.com/welcome.mp3' });
6
7// Start on default host/port (0.0.0.0:3000)
8await service.serve();
9
10// Or override host and port
11// await service.serve('127.0.0.1', 8080);