serveStaticFiles

View as MarkdownOpen in Claude

Serve static files (HTML, CSS, JS, images) from a local directory. Includes path traversal protection, MIME type detection, and security headers (Cache-Control, X-Content-Type-Options).

This method is useful for serving a web frontend alongside your agents — for example, an admin dashboard or a configuration UI.

Parameters

directory
stringRequired

Path to the directory containing static files. Can be absolute or relative (resolved via path.resolve() at registration time).

route
stringDefaults to /static

URL path prefix for static files.

Returns

void

Example

1import { AgentBase, AgentServer } from '@signalwire/sdk';
2
3const support = new AgentBase({ name: 'support', route: '/support' });
4support.setPromptText('You are a helpful assistant.');
5
6const server = new AgentServer({ port: 3000 });
7server.register(support);
8server.serveStaticFiles('./web', '/static');
9await server.run();

With this configuration:

Request PathServed By
/supportSupportAgent
/support/swaigSupportAgent SWAIG endpoint
/static/style.css./web/style.css
/static/logo.png./web/logo.png

Path traversal attempts (e.g., /../etc/passwd) are blocked. The resolved file path must remain within the configured static directory.