Skip Navigation
ClassClass

PreviewServer

An HTTP/1.1 server for previewing static documentation locally.

actor PreviewServer

Overview

This actor provides a simple, development-focused HTTP server that serves files from a specified directory. It uses SwiftNIO with async/await for modern Swift concurrency support.

Overview

PreviewServer is designed for local development use only. It binds to localhost and serves static files without TLS encryption. The server uses NIOAsyncChannel to bridge NIO’s event-driven architecture with Swift’s structured concurrency.

Usage

Create a server instance and call run() to start serving:

let server = PreviewServer(
    rootDirectory: URL(fileURLWithPath: "/path/to/docs"),
    port: 8080
)
try await server.run()

The server runs until the process is terminated (typically via Ctrl+C).

Topics

Relationships

  • Swift.Sendable
  • Swift.SendableMetatype
  • _Concurrency.Actor