Documentation Language: Swift

Class

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

Creating a Server

?
init(rootDirectory:port:)

Creates a new preview server.

Running the Server

F
run()

Starts the HTTP server and processes connections until termination.

Properties

V
rootDirectory

The directory containing files to serve.

V
port

The port to listen on for incoming HTTP connections.

Default Implementations

Relationships

Conforms To