# LiveHtmlServer

> Documentation for Redweb 0.16.1. Install that exact version when following these examples.

Lower-level server-rendered page host. Prefer defineApp({ pages, sockets }) and app.run() to compose a new application; LiveHtmlServer remains available for direct page-host lifecycle integration.

## Explain it like I’m five

LiveHtmlServer is a stage manager for server-rendered pages. It serves the first complete HTML scene, then carries approved actions backstage and sends updated pieces back.

## When should I use it?

Use defineApp for the normal application entry point. Construct LiveHtmlServer directly only when you need to own its lower-level listener and shutdown behavior.

## Follow the example

This API pattern illustrates the named surface; it may require application-owned classes, credentials, or assets. Start from a complete recipe for a runnable application.

```tsx
import { LiveHtmlServer } from 'redweb'
import { DocsPage, StatusPage } from './pages.js'

const server = new LiveHtmlServer({
  pages: [DocsPage, StatusPage],
  port: 8080,
  heartbeat: { intervalMs: 15_000, timeoutMs: 10_000 },
})
```

1. HTTP rendering creates complete HTML and binds a stable page identity.
2. The generated live socket accepts only declared actions for that page.
3. State changes produce bounded updates while authentication and resource limits cover both transports.

## Options

- pages: non-empty array of classes decorated with page()
- templateRoot: optional root for colocated HTML and CSS assets
- sessionTtlMs and maxSessions: bound pending and reconnectable sessions
- maxConcurrentRenders: independent HTTP render concurrency ceiling
- heartbeat: detects half-open browser connections
- authenticate: binds HTTP renders and socket upgrades to one stable identity
- origins: exact allowlist or asynchronous origin predicate

## Methods and members

### constructor(options)

Builds the page renderer, HTTP routes, generated assets, and live WebSocket route on one listener.

### shutdown()

Aborts active renders, drains routes, disposes pages and components, and closes owned resources.

## What should I watch for?

Decide deliberately whether page state is per connection or shared. Authenticate both HTTP and upgrade paths with the same identity and cap render concurrency.
