UNPKG

kist

Version:

Package Pipeline Processor

96 lines (95 loc) 3.15 kB
import { AbstractProcess } from "../core/abstract/AbstractProcess"; /** * LiveServer class provides functionality to serve static files, * inject live reload scripts into HTML responses, and manage WebSocket * connections to enable live reload capabilities. */ export declare class LiveServer extends AbstractProcess { /** * Express application */ private app; /** * The underlying HTTP server used by the LiveServer. * Handles incoming HTTP requests and serves static files. */ private server; /** * The WebSocket server responsible for managing WebSocket connections. * Enables real-time communication with connected clients. */ private wss; /** * A set of WebSocket clients currently connected to the server. * Each client represents an active WebSocket connection. */ private clients; /** * The port number on which the server is running. * Defaults to 3000 if not specified in the configuration. */ private port; /** * The root directory from which static files are served. * Defaults to the "public" folder in the current working directory. */ private root; /** * An array of paths to watch for changes. * When a file within these paths changes, the server triggers live reload. */ private watchPaths; /** * An array of paths or patterns to ignore during file watching. * Prevents unnecessary reloads caused by changes in these paths. * Defaults to ignoring the "node_modules" directory. */ private ignoredPaths; /** * Initializes the LiveServer. // * @param port - The port on which the server will listen. */ constructor(); /** * Initializes the HTTP server and WebSocket server. */ private initializeServer; /** Logs initialization details for the LiveServer. */ private logInitializationDetails; /** * Sets up rate limiting middleware to prevent abuse of HTTP requests. */ private setupRateLimiter; /** * Sets up WebSocket handlers to manage client connections. */ private setupWebSocketHandlers; /** * Sets up middleware for serving static files and injecting the live * reload script into HTML files. */ private setupMiddleware; /** * Middleware function to inject the live reload script into HTML * responses. Prevents directory traversal attacks by sanitizing the * requested file path. * @param req - The HTTP request object. * @param res - The HTTP response object. * @param next - The next middleware function. */ private injectLiveReloadScript; /** * Sends a reload signal to all connected WebSocket clients. */ reloadClients(): void; /** * Gracefully shuts down the server and all WebSocket connections. */ shutdown(): Promise<void>; /** * Type guard to check if an error is an instance of NodeJS.ErrnoException. * @param error - The error to check. * @returns True if the error has a `code` property. */ private isErrnoException; }